//============================================================================================
/**
 * @file	zkn2_main.c
 * @brief	金銀図鑑画面 メイン処理
 * @author	Hiroyuki Nakamura
 * @date	08.08.26
 */
//============================================================================================
#include "common.h"

#include "poketool/poke_number.h"

#include "msgdata/msg.naix"
#include "msgdata/msg_zkn.h"

#include "fielddata/maptable/zone_id.h"

#include "application/zukanlist/zkn_world_text_data.h"
#include "application/zukanlist/zkn_gira.h"

#include "zkn2_main.h"
#include "zkn2_obj.h"
#include "zkn2_bmp.h"
#include "zkn2_seq.h"
#include "zkn2_list.h"
#include "zkn2_ui.h"
#include "zukan_gra.naix"

#include "zkn_data/zukan_hw_data_g.naix"
#include "zkn_data/zukan_data.naix"
#include "zkn_data/zukan_enc_gold.naix"

#include "zkn_data/zkn_rangeid_zoneid_link.dat"

#include "zkn2_enclist_sort.dat"


//============================================================================================
//	定数定義
//============================================================================================
#define	EXP_BUF_SIZE	( 1024 )	// テンポラリメッセージバッファサイズ

// ＢＧウィンドウフレームデータ
// ボタン：トップ
#define	BGWF_BTN_TOP_PX			( 0 )
#define	BGWF_BTN_TOP_PY			( 19 )
#define	BGWF_BTN_TOP_SX			( 32 )
#define	BGWF_BTN_TOP_SY			( 5 )
// ボタン：リスト
#define	BGWF_BTN_LIST_PX		( 0 )
#define	BGWF_BTN_LIST_PY		( 19 )
#define	BGWF_BTN_LIST_SX		( 32 )
#define	BGWF_BTN_LIST_SY		( 5 )
// タイトルロゴ：ジョウト
#define	BGWF_LOGO_JOHTO_PX		( 7 )
#define	BGWF_LOGO_JOHTO_PY		( 3 )
#define	BGWF_LOGO_JOHTO_SX		( 10 )
#define	BGWF_LOGO_JOHTO_SY		( 3 )
// タイトルロゴ：ぜんこく
#define	BGWF_LOGO_ZENKOKU_PX	( 7 )
#define	BGWF_LOGO_ZENKOKU_PY	( 3 )
#define	BGWF_LOGO_ZENKOKU_SX	( 10 )
#define	BGWF_LOGO_ZENKOKU_SY	( 3 )
// ラベル：リスト（言語・ポケモン名など）
#define	BGWF_LABEL_LIST_PX		( 0 )
#define	BGWF_LABEL_LIST_PY		( 15 )
#define	BGWF_LABEL_LIST_SX		( 32 )
#define	BGWF_LABEL_LIST_SY		( 4 )
// リスト背景
#define	BGWF_LIST_BG_PX		( 0 )
#define	BGWF_LIST_BG_PY		( 0 )
#define	BGWF_LIST_BG_SX		( 32 )
#define	BGWF_LIST_BG_SY		( 5 )
// ボタン：検索トップ
#define	BGWF_BTN_SEARCH_TOP_PX	( 0 )
#define	BGWF_BTN_SEARCH_TOP_PY	( 20 )
#define	BGWF_BTN_SEARCH_TOP_SX	( 32 )
#define	BGWF_BTN_SEARCH_TOP_SY	( 4 )
// ボタン：検索入力
#define	BGWF_BTN_SEARCH_INPUT_PX	( 0 )
#define	BGWF_BTN_SEARCH_INPUT_PY	( 20 )
#define	BGWF_BTN_SEARCH_INPUT_SX	( 32 )
#define	BGWF_BTN_SEARCH_INPUT_SY	( 4 )
// 検索条件ＢＧ
#define	BGWF_SEARCH_BG_PX	( 0 )
#define	BGWF_SEARCH_BG_PY	( 0 )
#define	BGWF_SEARCH_BG_SX	( 32 )
#define	BGWF_SEARCH_BG_SY	( 24 )
// ボタン：詳細トップ
#define	BGWF_BTN_DETAIL_PX	( 0 )
#define	BGWF_BTN_DETAIL_PY	( 20 )
#define	BGWF_BTN_DETAIL_SX	( 32 )
#define	BGWF_BTN_DETAIL_SY	( 4 )
// 詳細・分布ウィンドウ
#define	BGWF_ENCOUNT_WIN_PX	( 10 )
#define	BGWF_ENCOUNT_WIN_PY	( 11 )
#define	BGWF_ENCOUNT_WIN_SX	( 20 )
#define	BGWF_ENCOUNT_WIN_SY	( 4 )

// 全国／ジョウト切り替えスイッチスクリーン座標
#define	COVER_NULL_CHAR		( 0x16 )	// 塗りつぶしキャラ
#define	COVER_SWITCH_PX		( 3 )		// Ｘ座標
#define	COVER_SWITCH_PY		( 15 )		// Ｙ座標
#define	COVER_SWITCH_SX		( 26 )		// Ｘサイズ
#define	COVER_SWITCH_SY		( 2 )		// Ｙ座標

// リストページＢＧ作成定義
enum {
	ZKN2MAIN_LISTMOVE_NONE = 0,		// 動作なし（作成のみ）
	ZKN2MAIN_LISTMOVE_UP,			// 図鑑番号増加
	ZKN2MAIN_LISTMOVE_DOWN,			// 図鑑番号減少
};

// リストページ：ポケモンアイコン背景関連
#define	LIST_SCRN_MAKE_Y	( ZKN2_POKEICON_PUT_V_MAX * 2 )		// 作成ブロックＹサイズ
#define	LIST_SCRN_SX		( BGWF_LIST_BG_SX )					// スクリーンＸサイズ
#define	LIST_SCRN_SY		( BGWF_LIST_BG_SY * ZKN2_POKEICON_PUT_V_MAX * 2 )	// スクリーンＹサイズ
#define	LIST_SCRN_DATA_NUM	( BGWF_LIST_BG_SX * BGWF_LIST_BG_SY )	// １ラインのキャラ数
#define	LIST_CHAR_GET_BALL	( 2 )			// 捕獲ボールキャラ
#define	LIST_CHAR_GET_NUM	( 3 )			// 捕獲数字キャラ
#define	LIST_CHAR_SEE_BALL	( 13 )			// 発見ボールキャラ
#define	LIST_CHAR_SEE_NUM	( 14 )			// 未確認数字キャラ
#define	LIST_CHAR_PALETTE	( 1 << 12 )		// パレット
#define	LIST_CHAR_POS		( 4 )			// ボール配置位置
#define	LIST_CHAR_SIZE		( 5 )			// 次のグリッドまでのスペース
// キャラ配置位置取得
#define	LIST_CHAR_PUT(x,y)	( LIST_SCRN_DATA_NUM * y + LIST_SCRN_SX + LIST_CHAR_POS + LIST_CHAR_SIZE * x )


// 選択されているＢＧを切り替えるためのワーク
typedef struct {
	u8	px;
	u8	py;
	u8	sx;
	u8	sy;
}ZKN2MAIN_SEARCH_BG_SEL;

// 検索フォルムBG表示座標
#define	SEARCH_FORM_PX			( 2 )
#define	SEARCH_FORM_PY			( 5 )
#define	SEARCH_FORM_SX			( 4 )
#define	SEARCH_FORM_SY			( 4 )
#define	SEARCH_FORM_SPACE_X		( 6 )
#define	SEARCH_FORM_SPACE_Y		( 5 )
#define	SEARCH_FORM_X_MAX		( 5 )

// 検索名BG表示座標
#define	SEARCH_NAME_PX			( 1 )
#define	SEARCH_NAME_PY			( 5 )
#define	SEARCH_NAME_SX			( 2 )
#define	SEARCH_NAME_SY			( 2 )
#define	SEARCH_NAME_SPACE_X		( 3 )
#define	SEARCH_NAME_SPACE_Y		( 3 )
#define	SEARCH_NAME_Y_MAX		( 5 )

// 分布データ
#define ZKN_RANGEDATA_DAN_MORNING_ARC_S		(NARC_zukan_enc_gold_zkn_dan_range_morning_mons_000_mrang)
#define ZKN_RANGEDATA_DAN_NOON_ARC_S		(NARC_zukan_enc_gold_zkn_dan_range_noon_mons_000_mrang)
#define ZKN_RANGEDATA_DAN_NIGHT_ARC_S		(NARC_zukan_enc_gold_zkn_dan_range_night_mons_000_mrang)
#define ZKN_RANGEDATA_FLD_MORNING_ARC_S		(NARC_zukan_enc_gold_zkn_fld_range_morning_mons_000_mrang)
#define ZKN_RANGEDATA_FLD_NOON_ARC_S		(NARC_zukan_enc_gold_zkn_fld_range_noon_mons_000_mrang)
#define ZKN_RANGEDATA_FLD_NIGHT_ARC_S		(NARC_zukan_enc_gold_zkn_fld_range_night_mons_000_mrang)
#define ZKN_RANGEDATA_DAN_SPECIAL_ARC_S		(NARC_zukan_enc_gold_zkn_dan_range_special_mons_000_mrang)
#define ZKN_RANGEDATA_FLD_SPECIAL_ARC_S		(NARC_zukan_enc_gold_zkn_fld_range_special_mons_000_mrang)

// 分布取得ID
enum {
	ZKN2_ENC_DAN_MORNING = 0,
	ZKN2_ENC_DAN_NOON,
	ZKN2_ENC_DAN_NIGHT,
	ZKN2_ENC_DAN_SPECIAL,

	ZKN2_ENC_FLD_MORNING,
	ZKN2_ENC_FLD_NOON,
	ZKN2_ENC_FLD_NIGHT,
	ZKN2_ENC_FLD_SPECIAL,
};

#define	ENC_MAP_AREA_GRID_X		( 22 )			// 分布のエリアを分けるＸグリッド
#define	ENC_MAP_TYPE_DUNGEON	( 0x80000000 )	// 分布場所がダンジョン


//============================================================================================
//	プロトタイプ宣言
//============================================================================================
static void ListPageBgLoad( ZKN2_WORK * wk );
static void SearchPageBgLoad( ZKN2_WORK * wk );

static void SearchSelBgChg( ZKN2_WORK * wk, const ZKN2MAIN_SEARCH_BG_SEL * sel, BOOL flg );
static void SearchAreaZenkokuSet( ZKN2_WORK * wk );
static void SearchFormSelectPos( ZKN2_WORK * wk, u32 pos, BOOL flg );
static void SearchNameSelectPos( ZKN2_WORK * wk, u32 pos, BOOL flg );
static void SearchListBgPriorityChange( ZKN2_WORK * wk );

static void PlacePageBgLoad( ZKN2_WORK * wk );
static void SizePageBgLoad( ZKN2_WORK * wk );
//static void FormPageBgLoad( ZKN2_WORK * wk );
static void DetailRetPageBgLoad( ZKN2_WORK * wk );

static u8 SexFormGet( ZKN2_WORK * wk, int flg );

static void EncountDataLoad( ZKN2_ENCOUNT_MAP * enc, u32 mons, u32 type );
//static void EncountDataModeGet( ZKN2_WORK * wk, ZKN2_ENCOUNT_MAP * make, ZKN2_ENCOUNT_MAP * dat, u32 mode );
static void FldEncDataModeGet( ZKN2_WORK * wk, ZKN2_ENCOUNT_MAP * dat, u32 mode, u32 type );
static void DanEncDataModeGet( ZKN2_WORK * wk, ZKN2_ENCOUNT_MAP * dat, u32 mode, u32 start, u32 type );
static void EncListSort( ZKN2_WORK * wk );


//============================================================================================
//	グローバル変数
//============================================================================================

// VRAM割り振り
static const GF_BGL_DISPVRAM VramTbl = {
	GX_VRAM_BG_128_B,				// メイン2DエンジンのBG
	GX_VRAM_BGEXTPLTT_NONE,			// メイン2DエンジンのBG拡張パレット

	GX_VRAM_SUB_BG_128_C,			// サブ2DエンジンのBG
	GX_VRAM_SUB_BGEXTPLTT_NONE,		// サブ2DエンジンのBG拡張パレット

	GX_VRAM_OBJ_64_E,				// メイン2DエンジンのOBJ
	GX_VRAM_OBJEXTPLTT_NONE,		// メイン2DエンジンのOBJ拡張パレット

	GX_VRAM_SUB_OBJ_16_I,			// サブ2DエンジンのOBJ
	GX_VRAM_SUB_OBJEXTPLTT_NONE,	// サブ2DエンジンのOBJ拡張パレット

	GX_VRAM_TEX_0_A,				// テクスチャイメージスロット
	GX_VRAM_TEXPLTT_01_FG			// テクスチャパレットスロット
};

// 言語チェックテーブル
static const u8 LangCheckParam[] = {
	LANG_JAPAN,
	LANG_ENGLISH,
	LANG_FRANCE,
	LANG_ITALY,
	LANG_GERMANY,
	LANG_SPAIN,
};

// 検索：並び順の選択ＢＧ位置
static const ZKN2MAIN_SEARCH_BG_SEL SearchRowSel[] =
{
	{  3,  6, 11, 2 },
	{ 18,  6, 11, 2 },
	{  3, 10, 11, 2 },
	{ 18, 10, 11, 2 },
	{  3, 14, 11, 2 },
	{ 18, 14, 11, 2 },
};

// 検索：タイプの選択ＢＧ位置
static const ZKN2MAIN_SEARCH_BG_SEL SearchTypeSel[] =
{
	{ 0,  5, 8, 2 }, { 8,  5, 8, 2 }, { 16,  5, 8, 2 }, { 24,  5, 8, 2 },
	{ 0,  8, 8, 2 }, { 8,  8, 8, 2 }, { 16,  8, 8, 2 }, { 24,  8, 8, 2 },
	{ 0, 11, 8, 2 }, { 8, 11, 8, 2 }, { 16, 11, 8, 2 }, { 24, 11, 8, 2 },
	{ 0, 14, 8, 2 }, { 8, 14, 8, 2 }, { 16, 14, 8, 2 }, { 24, 14, 8, 2 },
	{ 0, 17, 8, 2 }, { 8, 17, 8, 2 },
};

// 検索：地域の選択ＢＧ位置
static const ZKN2MAIN_SEARCH_BG_SEL SearchAreaSel[] =
{
	{  6,  8, 7, 2 },
	{ 19,  8, 7, 2 },
	{  6, 15, 7, 2 },
	{ 19, 15, 7, 2 },
};

// 検索名文字番号テーブル
static const u8 SearchNamePosTbl[] = {
	 0,  1,  2,  3,  4,		// ア
	 5,  6,  7,  8,  9,		// カ
	10, 11, 12, 13, 14,		// サ
	15, 16, 17, 18, 19,		// タ
	20, 21, 22, 23, 24,		// ナ
	25, 26, 27, 28, 29,		// ハ
	30, 31, 32, 33, 34,		// マ
	35,     37,     39,		// ヤ
	40, 41, 42, 43, 44,		// ラ
	45, 46,					// ワ
};



//--------------------------------------------------------------------------------------------
/**
 * VBLANK関数
 *
 * @param	work	図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_VBlank( void * work )
{
	ZKN2_WORK * wk = work;

	PaletteFadeTrans( wk->pfd );

	SearchListBgPriorityChange( wk );

	GF_BGL_VBlankFunc( wk->bgl );

	CATS_RenderOamTrans();

	OS_SetIrqCheckFlag( OS_IE_V_BLANK );
}

//--------------------------------------------------------------------------------------------
/**
 * VRAM設定
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_VramBankSet(void)
{
	GF_Disp_SetBank( &VramTbl );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧ初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_BgInit( ZKN2_WORK * wk )
{
	wk->bgl = GF_BGL_BglIniAlloc( HEAPID_ZUKAN );

	{	// BG SYSTEM
		GF_BGL_SYS_HEADER sysh = {
			GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BGMODE_0, GX_BG0_AS_2D,
		};
		GF_BGL_InitBG( &sysh );
	}

	{	// メイン画面：カバー
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x1000, 0, GF_BGL_SCRSIZ_512x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf000, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			2, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_COVER_M, &cnth, GF_BGL_MODE_TEXT );
		ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_M );
		GF_BGL_ClearCharSet( ZKN2_BGF_COVER_M, 0x20, 0, HEAPID_ZUKAN );
	}
	{	// メイン画面：上層
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xe800, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_UPPER_M, &cnth, GF_BGL_MODE_TEXT );
		ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_M );
		GF_BGL_ClearCharSet( ZKN2_BGF_UPPER_M, 0x20, 0, HEAPID_ZUKAN );
	}
	{	// メイン画面：中層
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xe000, GX_BG_CHARBASE_0x14000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_CENTER_M, &cnth, GF_BGL_MODE_TEXT );
		ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_M );
		GF_BGL_ClearCharSet( ZKN2_BGF_CENTER_M, 0x20, 0, HEAPID_ZUKAN );
	}
	{	// メイン画面：下層
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xd800, GX_BG_CHARBASE_0x18000, GX_BG_EXTPLTT_01,
			3, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_UNDER_M, &cnth, GF_BGL_MODE_TEXT );
		ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UNDER_M );
		GF_BGL_ClearCharSet( ZKN2_BGF_UNDER_M, 0x20, 0, HEAPID_ZUKAN );
	}

	{	// サブ画面：カバー
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x1000, 0, GF_BGL_SCRSIZ_512x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf000, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_COVER_S, &cnth, GF_BGL_MODE_TEXT );
		ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_S );
		GF_BGL_ClearCharSet( ZKN2_BGF_COVER_S, 0x20, 0, HEAPID_ZUKAN );
	}
	{	// サブ画面：上層
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xe800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_UPPER_S, &cnth, GF_BGL_MODE_TEXT );
		ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_S );
		GF_BGL_ClearCharSet( ZKN2_BGF_UPPER_S, 0x20, 0, HEAPID_ZUKAN );
	}
	{	// サブ画面：中層
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xe000, GX_BG_CHARBASE_0x14000, GX_BG_EXTPLTT_01,
			2, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_CENTER_S, &cnth, GF_BGL_MODE_TEXT );
		ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_S );
		GF_BGL_ClearCharSet( ZKN2_BGF_CENTER_S, 0x20, 0, HEAPID_ZUKAN );
	}
	{	// サブ画面：下層
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xd800, GX_BG_CHARBASE_0x18000, GX_BG_EXTPLTT_01,
			3, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_UNDER_S, &cnth, GF_BGL_MODE_TEXT );
		ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UNDER_S );
		GF_BGL_ClearCharSet( ZKN2_BGF_UNDER_S, 0x20, 0, HEAPID_ZUKAN );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面：大きさページ用ＢＧ切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	flg		切り替えフラグ ( TRUE = 大きさページ )
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SizePageBgChange( ZKN2_WORK * wk, BOOL flg )
{
	GF_BGL_BGControlExit( wk->bgl, ZKN2_BGF_UNDER_S );

	if( flg == FALSE ){
		{	// BG SYSTEM
			GF_BGL_SYS_HEADER sysh = {
				GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BGMODE_0, GX_BG0_AS_2D,
			};
			GF_BGL_InitBGDisp( &sysh, GF_BGL_SUB_DISP );
		}
//	    GXS_SetGraphicsMode( GX_BGMODE_0 );

		{	// サブ画面：下層
			GF_BGL_BGCNT_HEADER cnth= {
				0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xd800, GX_BG_CHARBASE_0x18000, GX_BG_EXTPLTT_01,
				3, 0, 0, FALSE
			};
			GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_UNDER_S, &cnth, GF_BGL_MODE_TEXT );
			ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UNDER_S );
			GF_BGL_ClearCharSet( ZKN2_BGF_UNDER_S, 0x20, 0, HEAPID_ZUKAN );
		}
	}else{
		{	// BG SYSTEM
			GF_BGL_SYS_HEADER sysh = {
				GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BGMODE_1, GX_BG0_AS_2D,
			};
			GF_BGL_InitBGDisp( &sysh, GF_BGL_SUB_DISP );
		}
//	    GXS_SetGraphicsMode( GX_BGMODE_1 );

		{	// サブ画面：下層
			GF_BGL_BGCNT_HEADER cnth= {
				0, 0, 0x400, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_256,
				GX_BG_SCRBASE_0xd800, GX_BG_CHARBASE_0x18000, GX_BG_EXTPLTT_01,
				2, 0, 0, FALSE
			};
			GF_BGL_BGControlSet( wk->bgl, ZKN2_BGF_UNDER_S, &cnth, GF_BGL_MODE_AFFINE );
			ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UNDER_S );
			GF_BGL_ClearCharSet( ZKN2_BGF_UNDER_S, 0x40, 0, HEAPID_ZUKAN );
		}
	}

	// GF_BGL_InitBGDisp()が全てOFFにしてしまうので、ONにする
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_BG0, VISIBLE_ON );
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_BG1, VISIBLE_ON );
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_BG2, VISIBLE_ON );
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_BG3, VISIBLE_ON );
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );
}


//--------------------------------------------------------------------------------------------
/**
 * ＢＧ解放
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_BgExit( ZKN2_WORK * wk )
{
	GF_BGL_BGControlExit( wk->bgl, ZKN2_BGF_UNDER_S );
	GF_BGL_BGControlExit( wk->bgl, ZKN2_BGF_CENTER_S );
	GF_BGL_BGControlExit( wk->bgl, ZKN2_BGF_UPPER_S );
	GF_BGL_BGControlExit( wk->bgl, ZKN2_BGF_COVER_S );
	GF_BGL_BGControlExit( wk->bgl, ZKN2_BGF_UNDER_M );
	GF_BGL_BGControlExit( wk->bgl, ZKN2_BGF_CENTER_M );
	GF_BGL_BGControlExit( wk->bgl, ZKN2_BGF_UPPER_M );
	GF_BGL_BGControlExit( wk->bgl, ZKN2_BGF_COVER_M );

	sys_FreeMemoryEz( wk->bgl );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧプライオリティ変更：トップ・リスト画面
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_TopListBgPriority(void)
{
	GF_BGL_PrioritySet( ZKN2_BGF_COVER_M, 2 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_M, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_M, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_M, 3 );

	GF_BGL_PrioritySet( ZKN2_BGF_COVER_S, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_S, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_S, 2 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_S, 3 );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧプライオリティ変更：検索画面
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchBgPriority(void)
{
	GF_BGL_PrioritySet( ZKN2_BGF_COVER_M, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_M, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_M, 2 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_M, 3 );

	GF_BGL_PrioritySet( ZKN2_BGF_COVER_S, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_S, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_S, 2 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_S, 3 );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧプライオリティ変更：詳細画面姿ページ
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_DetailBgPriority(void)
{
	GF_BGL_PrioritySet( ZKN2_BGF_COVER_M, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_M, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_M, 2 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_M, 3 );

	GF_BGL_PrioritySet( ZKN2_BGF_COVER_S, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_S, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_S, 2 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_S, 3 );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧプライオリティ変更：詳細画面分布ページ
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_PlaceBgPriority(void)
{
	GF_BGL_PrioritySet( ZKN2_BGF_COVER_M, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_M, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_M, 2 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_M, 3 );

	GF_BGL_PrioritySet( ZKN2_BGF_COVER_S, 3 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_S, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_S, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_S, 2 );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧプライオリティ変更：詳細画面大きさページ
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SizeBgPriority(void)
{
	GF_BGL_PrioritySet( ZKN2_BGF_COVER_M, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_M, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_M, 2 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_M, 3 );

	GF_BGL_PrioritySet( ZKN2_BGF_COVER_S, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_S, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_S, 3 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_S, 2 );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧプライオリティ変更：詳細画面「戻る」ページ
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_DetailRetBgPriority(void)
{
	GF_BGL_PrioritySet( ZKN2_BGF_COVER_M, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_M, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_M, 2 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_M, 3 );

	GF_BGL_PrioritySet( ZKN2_BGF_COVER_S, 0 );
	GF_BGL_PrioritySet( ZKN2_BGF_UPPER_S, 1 );
	GF_BGL_PrioritySet( ZKN2_BGF_CENTER_S, 3 );
	GF_BGL_PrioritySet( ZKN2_BGF_UNDER_S, 2 );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧスクリーンクリア
 *
 * @param	wk		図鑑画面ワーク
 * @param	frm		ＢＧフレーム
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_BgScrClear( ZKN2_WORK * wk, u8 frm )
{
	u8	sx;

	if( frm == ZKN2_BGF_COVER_M || frm == ZKN2_BGF_COVER_S ){
		sx = 64;
	}else{
		sx = 32;
	}
	GF_BGL_ScrFill( wk->bgl, frm, 0, 0, 0, sx, 32, 0 );
	GF_BGL_LoadScreenV_Req( wk->bgl, frm );
}

//--------------------------------------------------------------------------------------------
/**
 * 半透明設定
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SetBlendAlpha(void)
{
	G2_SetBlendAlpha(
		GX_BLEND_PLANEMASK_NONE,
		GX_BLEND_PLANEMASK_BG0 | GX_BLEND_PLANEMASK_BG1 |
		GX_BLEND_PLANEMASK_BG2 | GX_BLEND_PLANEMASK_BG3,
		6, 10 );
}

//--------------------------------------------------------------------------------------------
/**
 * 分布用半透明設定
 *
 * @param	ev1		第１対象面のブレンド係数
 * @param	ev2		第２対象面のブレンド係数
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_EncountDataChgSetBlendAlpha( u8 ev1, u8 ev2 )
{
	G2_SetBlendAlpha( GX_BLEND_PLANEMASK_BG2, GX_BLEND_PLANEMASK_BG3, ev1, ev2 );
}

//--------------------------------------------------------------------------------------------
/**
 * パレットフェード初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_PaletteFadeInit( ZKN2_WORK * wk )
{
	wk->pfd = PaletteFadeInit( HEAPID_ZUKAN );
	PaletteAreaClear( PF_BIT_NORMAL_ALL, HEAPID_ZUKAN );
	PaletteFadeWorkAllocSet( wk->pfd, FADE_MAIN_BG, FADE_PAL_ALL_SIZE, HEAPID_ZUKAN );
	PaletteFadeWorkAllocSet( wk->pfd, FADE_SUB_BG, FADE_PAL_ALL_SIZE, HEAPID_ZUKAN );
	PaletteFadeWorkAllocSet( wk->pfd, FADE_MAIN_OBJ, FADE_PAL_ALL_SIZE, HEAPID_ZUKAN );
	PaletteFadeWorkAllocSet( wk->pfd, FADE_SUB_OBJ, FADE_PAL_ALL_SIZE, HEAPID_ZUKAN );
}

//--------------------------------------------------------------------------------------------
/**
 * パレットフェード解放
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_PaletteFadeExit( ZKN2_WORK * wk )
{
	PaletteFadeWorkAllocFree( wk->pfd, FADE_SUB_OBJ );
	PaletteFadeWorkAllocFree( wk->pfd, FADE_MAIN_OBJ );
	PaletteFadeWorkAllocFree( wk->pfd, FADE_SUB_BG );
	PaletteFadeWorkAllocFree( wk->pfd, FADE_MAIN_BG );
	PaletteFadeFree( wk->pfd );
}

//--------------------------------------------------------------------------------------------
/**
 * メッセージ関連初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_MsgInit( ZKN2_WORK * wk )
{
	wk->mman   = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_zkn_dat, HEAPID_ZUKAN );
	wk->wset   = WORDSET_Create( HEAPID_ZUKAN );
	wk->expbuf = STRBUF_Create( EXP_BUF_SIZE, HEAPID_ZUKAN );
}

//--------------------------------------------------------------------------------------------
/**
 * メッセージ関連解放
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_MsgExit( ZKN2_WORK * wk )
{
	STRBUF_Delete( wk->expbuf );
	WORDSET_Delete( wk->wset );
	MSGMAN_Delete( wk->mman );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索データ読み込み
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchDataLoad( ZKN2_WORK * wk )
{
	ARCHANDLE * ah = ArchiveDataHandleOpen( ARC_ZUKAN_HW_DATA, HEAPID_ZUKAN );

	wk->hw_dot = ArcUtil_HDL_Load(
						ah,
						NARC_zukan_hw_data_g_zkn_hw_dot_dat,
						FALSE,
						HEAPID_ZUKAN,
						ALLOC_TOP );
	wk->area_dat = ArcUtil_HDL_Load(
						ah,
						NARC_zukan_hw_data_g_zkn_search_area_dat,
						FALSE,
						HEAPID_ZUKAN,
						ALLOC_TOP );

	ArchiveDataHandleClose( ah );
}

//--------------------------------------------------------------------------------------------
/**
 * 高さ・重さデータ解放
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchDataFree( ZKN2_WORK * wk )
{
	sys_FreeMemoryEz( wk->area_dat );
	sys_FreeMemoryEz( wk->hw_dot );
}


//--------------------------------------------------------------------------------------------
/**
 * ＢＧウィンドウフレーム作成
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_BgWinFrmInit( ZKN2_WORK * wk )
{
	wk->wfrm = BGWINFRM_Create( wk->bgl, BGWINFRM_TRANS_VBLANK, ZKN2_BGWF_MAX, HEAPID_ZUKAN );

	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_BTN_TOP, ZKN2_BGF_CENTER_M, BGWF_BTN_TOP_SX, BGWF_BTN_TOP_SY );
	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_BTN_LIST, ZKN2_BGF_CENTER_M, BGWF_BTN_LIST_SX, BGWF_BTN_LIST_SY );
	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_LOGO_JOHTO, ZKN2_BGF_COVER_M, BGWF_LOGO_JOHTO_SX, BGWF_LOGO_JOHTO_SY );
	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_LOGO_ZENKOKU, ZKN2_BGF_COVER_M, BGWF_LOGO_ZENKOKU_SX, BGWF_LOGO_ZENKOKU_SY );
	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_LABEL_LIST, ZKN2_BGF_CENTER_M, BGWF_LABEL_LIST_SX, BGWF_LABEL_LIST_SY );
	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_LIST_BG, ZKN2_BGF_UNDER_M, BGWF_LIST_BG_SX, BGWF_LIST_BG_SY );
	BGWINFRM_Add(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_TOP,
		ZKN2_BGF_UPPER_M, BGWF_BTN_SEARCH_TOP_SX, BGWF_BTN_SEARCH_TOP_SY );
	BGWINFRM_Add(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_INPUT,
		ZKN2_BGF_UPPER_M, BGWF_BTN_SEARCH_INPUT_SX, BGWF_BTN_SEARCH_INPUT_SY );
	BGWINFRM_Add(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_LIST,
		ZKN2_BGF_CENTER_M, BGWF_BTN_LIST_SX, BGWF_BTN_LIST_SY );
	BGWINFRM_Add(
		wk->wfrm, ZKN2_BGWF_SEARCH_BG_D1, ZKN2_BGF_COVER_M, BGWF_SEARCH_BG_SX, BGWF_SEARCH_BG_SY );
	BGWINFRM_Add(
		wk->wfrm, ZKN2_BGWF_SEARCH_BG_D2, ZKN2_BGF_CENTER_M, BGWF_SEARCH_BG_SX, BGWF_SEARCH_BG_SY );
	BGWINFRM_Add(
		wk->wfrm, ZKN2_BGWF_SEARCH_BG_U1, ZKN2_BGF_UPPER_S, BGWF_SEARCH_BG_SX, BGWF_SEARCH_BG_SY );
	BGWINFRM_Add(
		wk->wfrm, ZKN2_BGWF_SEARCH_BG_U2, ZKN2_BGF_CENTER_S, BGWF_SEARCH_BG_SX, BGWF_SEARCH_BG_SY );

	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_SEARCH_COVER_U, ZKN2_BGF_COVER_S, 32, 24 );
	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_SEARCH_COVER_D, ZKN2_BGF_COVER_M, 32, 24 );
	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_SEARCH_COVER_H, ZKN2_BGF_COVER_M, 3, 24 );

	BGWINFRM_Add( wk->wfrm, ZKN2_BGWF_BTN_DETAIL, ZKN2_BGF_UPPER_M, BGWF_BTN_DETAIL_SX, BGWF_BTN_DETAIL_SY );

	BGWINFRM_Add(
		wk->wfrm, ZKN2_BGWF_ENCOUNT_WIN, ZKN2_BGF_UNDER_S, BGWF_ENCOUNT_WIN_SX, BGWF_ENCOUNT_WIN_SY );

	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_BTN_TOP,
		wk->graphic_ah, NARC_zukan_gra_btn_top_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_BTN_LIST,
		wk->graphic_ah, NARC_zukan_gra_btn_list_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_LOGO_JOHTO,
		wk->graphic_ah, NARC_zukan_gra_logo_johto_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_LOGO_ZENKOKU,
		wk->graphic_ah, NARC_zukan_gra_logo_zenkoku_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_LABEL_LIST,
		wk->graphic_ah, NARC_zukan_gra_label_list_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_LIST_BG,
		wk->graphic_ah, NARC_zukan_gra_list_block_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_TOP,
		wk->graphic_ah, NARC_zukan_gra_btn_search01_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_INPUT,
		wk->graphic_ah, NARC_zukan_gra_btn_search02_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_LIST,
		wk->graphic_ah, NARC_zukan_gra_btn_list_search_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_SEARCH_COVER_U,
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_top_s_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_BTN_DETAIL,
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_btn02_m_lz_NSCR, TRUE );
	BGWINFRM_FrameSetArcHandle(
		wk->wfrm, ZKN2_BGWF_ENCOUNT_WIN,
		wk->graphic_ah, NARC_zukan_gra_bunpu_win_lz_NSCR, TRUE );

	BGWINFRM_PutAreaSet( wk->wfrm, ZKN2_BGWF_SEARCH_BG_U1, 0, 32, 0, 19 );
	BGWINFRM_PutAreaSet( wk->wfrm, ZKN2_BGWF_SEARCH_BG_U2, 0, 32, 0, 19 );

//	ZKN2BMP_SearchBmpBgWinFrmSet( wk );

	ZKN2BMP_DetailListBGWFAdd( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧウィンドウフレーム削除
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_BgWinFrmExit( ZKN2_WORK * wk )
{
	BGWINFRM_Exit( wk->wfrm );
}

//--------------------------------------------------------------------------------------------
/**
 * トップボタン・フレームイン開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_TopButtonInStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_BTN_TOP, BGWF_BTN_TOP_PX, BGWF_BTN_TOP_PY+BGWF_BTN_TOP_SY );
	BGWINFRM_MoveInit( wk->wfrm, ZKN2_BGWF_BTN_TOP, 0, -1, BGWF_BTN_TOP_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * トップボタン・フレームアウト開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_TopButtonOutStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_BTN_TOP, BGWF_BTN_TOP_PX, BGWF_BTN_TOP_PY );
	BGWINFRM_MoveInit( wk->wfrm, ZKN2_BGWF_BTN_TOP, 0, 1, BGWF_BTN_TOP_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * リストラベル表示
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_ListLabelPut( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_LABEL_LIST, BGWF_LABEL_LIST_PX, BGWF_LABEL_LIST_PY );
}

//--------------------------------------------------------------------------------------------
/**
 * リストボタン・フレームイン開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_ListButtonInStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_BTN_LIST, BGWF_BTN_LIST_PX, BGWF_BTN_LIST_PY+BGWF_BTN_LIST_SY );
	BGWINFRM_MoveInit( wk->wfrm, ZKN2_BGWF_BTN_LIST, 0, -1, BGWF_BTN_LIST_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * リストボタン・フレームアウト開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_ListButtonOutStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_BTN_LIST, BGWF_BTN_LIST_PX, BGWF_BTN_LIST_PY );
	BGWINFRM_MoveInit( wk->wfrm, ZKN2_BGWF_BTN_LIST, 0, 1, BGWF_BTN_LIST_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索トップボタン・フレームイン開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchTopButtonInStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_TOP,
		BGWF_BTN_SEARCH_TOP_PX, BGWF_BTN_SEARCH_TOP_PY+BGWF_BTN_SEARCH_TOP_SY );
	BGWINFRM_MoveInit(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_TOP, 0, -1, BGWF_BTN_SEARCH_TOP_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索トップボタン・フレームアウト開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchTopButtonOutStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_TOP,
		BGWF_BTN_SEARCH_TOP_PX, BGWF_BTN_SEARCH_TOP_PY );
	BGWINFRM_MoveInit(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_TOP, 0, 1, BGWF_BTN_SEARCH_TOP_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索入力ボタン・フレームイン開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchInputButtonInStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_INPUT,
		BGWF_BTN_SEARCH_INPUT_PX, BGWF_BTN_SEARCH_INPUT_PY+BGWF_BTN_SEARCH_INPUT_SY );
	BGWINFRM_MoveInit(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_INPUT, 0, -1, BGWF_BTN_SEARCH_INPUT_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索入力ボタン・フレームアウト開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchInputButtonOutStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_INPUT,
		BGWF_BTN_SEARCH_INPUT_PX, BGWF_BTN_SEARCH_INPUT_PY );
	BGWINFRM_MoveInit(
		wk->wfrm, ZKN2_BGWF_BTN_SEARCH_INPUT, 0, 1, BGWF_BTN_SEARCH_INPUT_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索リストボタン・フレームイン開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchListButtonInStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_BTN_SEARCH_LIST, BGWF_BTN_LIST_PX, BGWF_BTN_LIST_PY+BGWF_BTN_LIST_SY );
	BGWINFRM_MoveInit( wk->wfrm, ZKN2_BGWF_BTN_SEARCH_LIST, 0, -1, BGWF_BTN_LIST_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索リストボタン・フレームアウト開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchListButtonOutStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_BTN_SEARCH_LIST, BGWF_BTN_LIST_PX, BGWF_BTN_LIST_PY );
	BGWINFRM_MoveInit( wk->wfrm, ZKN2_BGWF_BTN_SEARCH_LIST, 0, 1, BGWF_BTN_LIST_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面ボタン・フレームイン開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_DetailButtonInStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut(
		wk->wfrm, ZKN2_BGWF_BTN_DETAIL,
		BGWF_BTN_DETAIL_PX, BGWF_BTN_DETAIL_PY+BGWF_BTN_DETAIL_SY );
	BGWINFRM_MoveInit( wk->wfrm, ZKN2_BGWF_BTN_DETAIL, 0, -1, BGWF_BTN_DETAIL_SY );
}


//--------------------------------------------------------------------------------------------
/**
 * 詳細画面ボタン・フレームアウト開始
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_DetailButtonOutStart( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut(
		wk->wfrm, ZKN2_BGWF_BTN_DETAIL, BGWF_BTN_DETAIL_PX, BGWF_BTN_DETAIL_PY );
	BGWINFRM_MoveInit( wk->wfrm, ZKN2_BGWF_BTN_DETAIL, 0, 1, BGWF_BTN_DETAIL_SY );
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面のボタンパレット変更
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_DetailButtonPalChange( ZKN2_WORK * wk )
{
	u16 * scrn;
	u32	i, j;
	u16	pal;

	scrn = BGWINFRM_FrameBufGet( wk->wfrm, ZKN2_BGWF_BTN_DETAIL );

	if( ZukanWork_GetPokeGetFlag(wk->dat->zukan_work,wk->detail_mons) ){
		pal = 0;
	}else{
		pal = 0xb000;
	}

	for( i=0; i<BGWF_BTN_DETAIL_SY; i++ ){
		for( j=8; j<16; j++ ){
			scrn[i*BGWF_BTN_DETAIL_SX+j] = ( scrn[i*BGWF_BTN_DETAIL_SX+j] & 0xfff ) | pal;
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面分布ページの「せいそくちふめい」表示
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_EncountWinPut( ZKN2_WORK * wk )
{
	BGWINFRM_FramePut(
		wk->wfrm, ZKN2_BGWF_ENCOUNT_WIN, BGWF_ENCOUNT_WIN_PX, BGWF_ENCOUNT_WIN_PY );
	GF_BGL_BmpWinOnVReq( &wk->win[ZKN2_BMPWIN_ENC_U_ERROR] );
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面分布ページの「せいそくちふめい」非表示
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_EncountWinOff( ZKN2_WORK * wk )
{
	BGWINFRM_FrameOff( wk->wfrm, ZKN2_BGWF_ENCOUNT_WIN );
	GF_BGL_BmpWinOffVReq( &wk->win[ZKN2_BMPWIN_ENC_U_ERROR] );
}

//--------------------------------------------------------------------------------------------
/**
 * ページごとの初期化処理
 *
 * @param	wk		図鑑画面ワーク
 * @param	page	ページ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_PageInit( ZKN2_WORK * wk, u32 page )
{
	switch( page ){
	case ZKN_PAGE_LIST:		// トップ/リスト
		ListPageBgLoad( wk );
		ZKN2MAIN_TopListBgPriority();
		ZKN2BMP_ListPageInit( wk );
		ZKN2OBJ_ListPageInit( wk );
		break;

	case ZKN_PAGE_PLACE:	// 詳細：分布
		PlacePageBgLoad( wk );
		ZKN2MAIN_PlaceBgPriority();
		ZKN2BMP_PlacePageInit( wk );
		ZKN2OBJ_PlacePageInit( wk );
		break;

	case ZKN_PAGE_SIZE:		// 詳細：大きさ
		SizePageBgLoad( wk );
		ZKN2MAIN_SizeBgPriority();
		ZKN2BMP_SizePageInit( wk );
		ZKN2OBJ_SizePageInit( wk );
		break;

	case ZKN_PAGE_FORM:		// 詳細：姿
		ZKN2MAIN_FormPageBgLoad( wk );
		ZKN2MAIN_DetailBgPriority();
		ZKN2BMP_FormPageInit( wk );
		ZKN2OBJ_FormPageInit( wk );
		break;

	case ZKN_PAGE_RETURN:	// 詳細：戻る
		DetailRetPageBgLoad( wk );
		ZKN2MAIN_DetailRetBgPriority();
		ZKN2BMP_DetailRetPageInit( wk );
		break;

	case ZKN_PAGE_SEARCH:	// 検索
		SearchPageBgLoad( wk );
		ZKN2MAIN_SearchBgPriority();
		ZKN2BMP_SearchPageInit( wk );
		ZKN2OBJ_SearchPageInit( wk );
		break;
	}
}


//--------------------------------------------------------------------------------------------
/**
 * リストページのＢＧ読み込み
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ListPageBgLoad( ZKN2_WORK * wk )
{
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UNDER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_S );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_top_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_COVER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	{	// 検索画面からの復帰で不具合が出るので変更
		NNSG2dScreenData * scrn;
		void * buf;
		buf = ArcUtil_HDL_ScrnDataGet(
				wk->graphic_ah, NARC_zukan_gra_zukan_gs_top_m_lz_NSCR, TRUE, &scrn, HEAPID_ZUKAN );
		GF_BGL_ScreenBufSet( wk->bgl, ZKN2_BGF_COVER_M, (void *)scrn->rawData, 64*32*2 );
		sys_FreeMemoryEz( buf );
	}

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_btn01_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_list_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );
	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah, NARC_zukan_gra_zukan_gs_m_NCLR, HEAPID_ZUKAN, FADE_MAIN_BG, 0, 0 );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_top_s_lz_NCGR,
		wk->bgl, ZKN2_BGF_COVER_S, 0, 0, TRUE, HEAPID_ZUKAN );
	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_top_s_lz_NSCR,
		wk->bgl, ZKN2_BGF_COVER_S, 0, 0, TRUE, HEAPID_ZUKAN );
	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_list_s_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );
	if( wk->lang == PM_LANG ){
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_list01_s_lz_NSCR,
			wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );
	}else{
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_list03_s_lz_NSCR,
			wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );
	}
	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah, NARC_zukan_gra_zukan_gs_s_NCLR, HEAPID_ZUKAN, FADE_SUB_BG, 0, 0 );

	if( wk->zenkoku_mode == FALSE ){
		GF_BGL_ScrFill(
			wk->bgl, ZKN2_BGF_COVER_M, COVER_NULL_CHAR,
			COVER_SWITCH_PX, COVER_SWITCH_PY, COVER_SWITCH_SX, COVER_SWITCH_SY, GF_BGL_SCRWRT_PALNL );
	}

	ZKN2MAIN_ZukanNamePut( wk );

	BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_BTN_TOP, BGWF_BTN_TOP_PX, BGWF_BTN_TOP_PY );

	ZKN2MAIN_ListBgSet( wk );

	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_S );
}

//--------------------------------------------------------------------------------------------
/**
 * 図鑑タイトル表示
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_ZukanNamePut( ZKN2_WORK * wk )
{
	if( wk->zkn_mode == ZKN2_MODE_JOHTO ){
		BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_LOGO_JOHTO, BGWF_LOGO_JOHTO_PX, BGWF_LOGO_JOHTO_PY );
	}else{
		BGWINFRM_FramePut( wk->wfrm, ZKN2_BGWF_LOGO_ZENKOKU, BGWF_LOGO_ZENKOKU_PX, BGWF_LOGO_ZENKOKU_PY );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧに図鑑番号を配置
 *
 * @param	scrn	ＢＧスクリーンバッファ
 * @param	num		図鑑番号
 * @param	chr		キャラ番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ListBgNumPut( u16 * scrn, u16 num, u16 chr )
{
	u8	tbl[] = { 100, 10, 1 };
	u8	i;

	for( i=0; i<3; i++ ){
		scrn[i] = LIST_CHAR_PALETTE | ( chr + num / tbl[i] );
		num %= tbl[i];
	}
}

//--------------------------------------------------------------------------------------------
/**
 * リストページ：グリッドＢＧスクリーン作成
 *
 * @param	wk		図鑑画面ワーク
 * @param	start	開始図鑑番号
 *
 * @return	作成したバッファ
 */
//--------------------------------------------------------------------------------------------
u16 * ZKN2MAIN_ListBgScreenMake( ZKN2_WORK * wk, u32 start )
{
	u16 * scrn;
	u16 * wfrm;
	u32	pos;
	u32	max;
	u16	i, j;

	scrn = sys_AllocMemoryLo( HEAPID_ZUKAN, sizeof(u16) * LIST_SCRN_SX * LIST_SCRN_SY );
	wfrm = BGWINFRM_FrameBufGet( wk->wfrm, ZKN2_BGWF_LIST_BG );

	max = ZKN2LIST_ListMaxGet( wk, TRUE );

	for( i=0; i<LIST_SCRN_MAKE_Y; i++ ){
		MI_CpuCopy16( wfrm, &scrn[LIST_SCRN_DATA_NUM*i], LIST_SCRN_DATA_NUM*2 );
		for( j=0; j<ZKN2_POKEICON_PUT_H_MAX; j++ ){
			pos = start + i * ZKN2_POKEICON_PUT_H_MAX + j;
			if( pos >= max ){
				break;
			}
			if( wk->list_put[pos].type == ZKN2LIST_REGTYPE_GET ){
				scrn[ LIST_CHAR_PUT(j,i)+0 ] = LIST_CHAR_PALETTE | LIST_CHAR_GET_BALL;
				ListBgNumPut( &scrn[ LIST_CHAR_PUT(j,i)+1 ], pos+1, LIST_CHAR_GET_NUM );
			}else if( wk->list_put[pos].type == ZKN2LIST_REGTYPE_SEE ){
//				scrn[ LIST_CHAR_PUT(j,i)+0 ] = LIST_CHAR_PALETTE | LIST_CHAR_SEE_BALL;
				ListBgNumPut( &scrn[ LIST_CHAR_PUT(j,i)+1 ], pos+1, LIST_CHAR_SEE_NUM );
			}else{
				ListBgNumPut( &scrn[ LIST_CHAR_PUT(j,i)+1 ], pos+1, LIST_CHAR_SEE_NUM );
			}
		}
	}

	return scrn;
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面のリスト：グリッドＢＧスクリーン作成
 *
 * @param	wk		図鑑画面ワーク
 * @param	start	開始図鑑番号
 *
 * @return	作成したバッファ
 */
//--------------------------------------------------------------------------------------------
u16 * ZKN2MAIN_SearchListBgScreenMake( ZKN2_WORK * wk, u32 start )
{
	u16 * scrn;
	u16 * wfrm;
	u32	pos;
//	u32	max;
	u32	num;
	u16	i, j;

	scrn = sys_AllocMemoryLo( HEAPID_ZUKAN, sizeof(u16) * LIST_SCRN_SX * LIST_SCRN_SY );
	wfrm = BGWINFRM_FrameBufGet( wk->wfrm, ZKN2_BGWF_LIST_BG );

//	max = ZKN2LIST_ListMaxGet( wk, FALSE );

	for( i=0; i<LIST_SCRN_MAKE_Y; i++ ){
		MI_CpuCopy16( wfrm, &scrn[LIST_SCRN_DATA_NUM*i], LIST_SCRN_DATA_NUM*2 );
		for( j=0; j<ZKN2_POKEICON_PUT_H_MAX; j++ ){
			pos = start + i * ZKN2_POKEICON_PUT_H_MAX + j;
//			if( pos >= max ){ break; }
			if( wk->list_put[pos].mons == 0 ){ continue; }

			num = PMNumber_GetPokeNumber( wk->zkn_mode, wk->list_put[pos].mons );

			if( wk->list_put[pos].type == ZKN2LIST_REGTYPE_GET ){
				scrn[ LIST_CHAR_PUT(j,i)+0 ] = LIST_CHAR_PALETTE | LIST_CHAR_GET_BALL;
				ListBgNumPut( &scrn[ LIST_CHAR_PUT(j,i)+1 ], num, LIST_CHAR_GET_NUM );
			}else if( wk->list_put[pos].type == ZKN2LIST_REGTYPE_SEE ){
				ListBgNumPut( &scrn[ LIST_CHAR_PUT(j,i)+1 ], num, LIST_CHAR_SEE_NUM );
			}else{
				ListBgNumPut( &scrn[ LIST_CHAR_PUT(j,i)+1 ], num, LIST_CHAR_SEE_NUM );
			}
		}
	}

	return scrn;
}

//--------------------------------------------------------------------------------------------
/**
 * リストページ：グリッドＢＧスクリーン解放
 *
 * @param	scrn	スクリーンバッファ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_ListBgScreenExit( u16 * scrn )
{
	sys_FreeMemoryEz( scrn );
}

//--------------------------------------------------------------------------------------------
/**
 * リストページ：現在のグリッドＢＧスクリーンをセット
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_ListBgSet( ZKN2_WORK * wk )
{
	u16 * scrn = ZKN2MAIN_ListBgScreenMake( wk, wk->list_scr * ZKN2_POKEICON_SEL_MAX );
	ZKN2MAIN_ListBgScrollPut( wk, scrn );
	ZKN2MAIN_ListBgScreenExit( scrn );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面のリスト：現在のグリッドＢＧスクリーンをセット
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchListBgSet( ZKN2_WORK * wk )
{
	u16 * scrn = ZKN2MAIN_SearchListBgScreenMake( wk, wk->list_scr * ZKN2_POKEICON_SEL_MAX );
	ZKN2MAIN_ListBgScrollPut( wk, scrn );
	ZKN2MAIN_ListBgScreenExit( scrn );
}

//--------------------------------------------------------------------------------------------
/**
 * リストページ：グリッドＢＧスクリーンを配置
 *
 * @param	wk		図鑑画面ワーク
 * @param	scrn	スクリーンバッファ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_ListBgScrollPut( ZKN2_WORK * wk, u16 * scrn )
{
	GF_BGL_ScrWrite( wk->bgl, ZKN2_BGF_UNDER_M, scrn, 0, 0, 32, 24 );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_M );
}


//--------------------------------------------------------------------------------------------
/**
 * 指定言語を表示できるかチェック
 *
 * @param	wk		図鑑画面ワーク
 * @param	mons	ポケモン番号
 * @param	lang	言語
 *
 * @retval	"TRUE = 可"
 * @retval	"FALSE = 不可"
 */
//--------------------------------------------------------------------------------------------
BOOL ZKN2MAIN_LangCheck( ZKN2_WORK * wk, u16 mons, u16 lang )
{
	if( ZukanWork_GetTextVersionUpMasterFlag(wk->dat->zukan_work) == FALSE ){
		return FALSE;
	}
	return ZukanWork_GetTextVersionUpFlag( wk->dat->zukan_work, mons, lang );
}

//--------------------------------------------------------------------------------------------
/**
 * 母国語以外を表示できるかチェック
 *
 * @param	wk		図鑑画面ワーク
 * @param	mons	ポケモン番号
 *
 * @retval	"TRUE = 可"
 * @retval	"FALSE = 不可"
 */
//--------------------------------------------------------------------------------------------
BOOL ZKN2MAIN_LangChangeCheck( ZKN2_WORK * wk, u16 mons )
{
	u32	i;

	for( i=0; i<NELEMS(LangCheckParam); i++ ){
		if( LangCheckParam[i] != PM_LANG &&
			ZKN2MAIN_LangCheck( wk, mons, LangCheckParam[i] ) == TRUE ){
			return TRUE;
		}
	}
	return FALSE;
}

//--------------------------------------------------------------------------------------------
/**
 * リストページ：言語切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	mons	ポケモン番号
 * @param	mv		切り替え方向
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_LangChange( ZKN2_WORK * wk, u16 mons, s16 mv )
{
	u32	i;
	s16	lang_t, lang_c;

	if( ZukanWork_GetTextVersionUpMasterFlag(wk->dat->zukan_work) == FALSE ){
		return;
	}

	lang_t = ZKN_WT_GetLANG_Code_ZKN_WORLD_TEXT_Code( wk->lang );

	for( i=0; i<ZKN_WORLD_TEXT_NUM; i++ ){
		lang_t += mv;
		if( lang_t < ZKN_WORLD_TEXT_JAPAN ){
			lang_t = ZKN_WORLD_TEXT_SPA;
		}else if( lang_t >= ZKN_WORLD_TEXT_NUM ){
			lang_t = ZKN_WORLD_TEXT_JAPAN;
		}
		lang_c = ZKN_WT_GetZKN_WORLD_TEXT_Code_LANG_Code( lang_t );
		if( lang_c == wk->lang ){
			break;
		}
		if( ZKN2MAIN_LangCheck( wk, mons, lang_c ) == TRUE || lang_c == PM_LANG ){
			u32	pos = ZKN2LIST_SelPosGet(wk);
			wk->lang = lang_c;
			// 言語表示切り替え
			ZKN2BMP_ListLabelPokeNamePut( wk, mons, ZKN2_BMPWIN_LIST_POKE );
			// 上画面表示切り替え
			ZKN2MAIN_PokeInfoBgPut( wk->bgl, ZKN2_BGF_UNDER_S, wk->lang, wk->graphic_ah, HEAPID_ZUKAN );
			ZKN2BMP_ListPokeTextPut( wk, mons, pos );
			// 言語アイコン
			ZKN2OBJ_ListMainLangIconChg( wk, mons, ZKN2_OBJ_LANGICON_M );
			ZKN2OBJ_ListSubLangIconChg( wk, mons, ZKN2_OBJ_LANGICON1 );
			// タイプアイコン
			ZKN2OBJ_TypeIconAnmChg( wk, mons, pos, ZKN2_OBJ_TYPEICON1 );
			// 足跡
			ZKN2OBJ_PokeFootChange( wk, mons, pos, ZKN2_OBJ_POKEFOOT );
			// ボール
			ZKN2OBJ_ListBallPut( wk, pos, ZKN2_OBJ_BALL_S );

			Snd_SePlay( SE_ZKN2_SELECT );
			break;
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * リストページ：選択ポケモン情報表示
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_ListSelPosInfoPut( ZKN2_WORK * wk )
{
	u32	pos;
	u16	mons;

	pos  = ZKN2LIST_SelPosGet( wk );
	mons = ZKN2LIST_SelMonsGet( wk );

	if( mons == 0 ){
		ZKN2OBJ_LangArrowVanish( wk, ZKN2_OBJ_ARROW_L, FALSE );
		ZKN2OBJ_ListLangVanish( wk, ZKN2_OBJ_LANGICON_M, FALSE );
	}else{
		if( ZKN2MAIN_LangChangeCheck( wk, mons ) == TRUE ){
			ZKN2OBJ_LangArrowVanish( wk, ZKN2_OBJ_ARROW_L, TRUE );
		}else{
			ZKN2OBJ_LangArrowVanish( wk, ZKN2_OBJ_ARROW_L, FALSE );
		}
		ZKN2OBJ_ListLangVanish( wk, ZKN2_OBJ_LANGICON_M, TRUE );
	}

	if( ZKN2MAIN_LangCheck( wk, mons, wk->lang ) == FALSE ){
		wk->lang = PM_LANG;
	}

	// BMP
	ZKN2BMP_ListLabelPokeNamePut( wk, mons, ZKN2_BMPWIN_LIST_POKE );
	ZKN2BMP_ListPokeInfoPut( wk, mons, pos );
	ZKN2BMP_ListPokeTextPut( wk, mons, pos );

	// OBJ
	// ポケモングラフィック
	ZKN2OBJ_PokeGraChange( wk, mons, ZKN2_OBJ_POKEGRA1, ZKN2_OBJ_NAZOPOKE_S );
	// 言語アイコン
	ZKN2OBJ_ListMainLangIconChg( wk, mons, ZKN2_OBJ_LANGICON_M );
	ZKN2OBJ_ListSubLangIconChg( wk, mons, ZKN2_OBJ_LANGICON1 );
	// タイプアイコン
	ZKN2OBJ_TypeIconAnmChg( wk, mons, pos, ZKN2_OBJ_TYPEICON1 );
	// 足跡
	ZKN2OBJ_PokeFootChange( wk, mons, pos, ZKN2_OBJ_POKEFOOT );
	// ボール
	ZKN2OBJ_ListBallPut( wk, pos, ZKN2_OBJ_BALL_S );

	// 空き番号のときの処理
	if( pos >= ZKN2LIST_ListMaxGet( wk, TRUE ) ){
		ZKN2MAIN_PokeInfoBgPutMax( wk->bgl, ZKN2_BGF_UNDER_S, wk->graphic_ah, HEAPID_ZUKAN );
		GF_BGL_BmpWinOffVReq( &wk->win[ZKN2_BMPWIN_LIST_U_TITLE] );
		ZKN2OBJ_Vanish( wk, ZKN2_OBJ_NAZOPOKE_S, FALSE );
	}else{
		ZKN2MAIN_PokeInfoBgPut( wk->bgl, ZKN2_BGF_UNDER_S, wk->lang, wk->graphic_ah, HEAPID_ZUKAN );
		GF_BGL_BmpWinOnVReq( &wk->win[ZKN2_BMPWIN_LIST_U_TITLE] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * リストページ：上画面ＢＧ切り替え
 *
 * @param	bgl		BGL
 * @param	bgfrm	ＢＧフレーム
 * @param	lang	言語
 * @param	ah		アークハンドル
 * @param	heapID	ヒープＩＤ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_PokeInfoBgPut( GF_BGL_INI * bgl, u8 bgfrm, u8 lang, ARCHANDLE * ah, u32 heapID )
{
	NNSG2dScreenData * scrn;
	void * buf;
	u32	file;

	if( lang == PM_LANG ){
		file = NARC_zukan_gra_zukan_gs_list01_s_lz_NSCR;
	}else{
		file = NARC_zukan_gra_zukan_gs_list03_s_lz_NSCR;
	}

	buf = ArcUtil_HDL_ScrnDataGet( ah, file, TRUE, &scrn, heapID );

	GF_BGL_ScrWrite( bgl, bgfrm, scrn->rawData, 0, 0, 32, 24 );
	GF_BGL_LoadScreenV_Req( bgl, bgfrm );

	sys_FreeMemoryEz( buf );
}

//--------------------------------------------------------------------------------------------
/**
 * リストページ：登録数以上のときの上画面ＢＧ
 *
 * @param	bgl		BGL
 * @param	bgfrm	ＢＧフレーム
 * @param	ah		アークハンドル
 * @param	heapID	ヒープＩＤ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_PokeInfoBgPutMax( GF_BGL_INI * bgl, u8 bgfrm, ARCHANDLE * ah, u32 heapID )
{
	NNSG2dScreenData * scrn;
	void * buf;

	buf = ArcUtil_HDL_ScrnDataGet(
			ah, NARC_zukan_gra_zukan_gs_list04_s_lz_NSCR, TRUE, &scrn, heapID );
	GF_BGL_ScrWrite( bgl, bgfrm, scrn->rawData, 0, 0, 32, 24 );
	GF_BGL_LoadScreenV_Req( bgl, bgfrm );
	sys_FreeMemoryEz( buf );
}


//============================================================================================
/*
	検索
*/
//============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * 検索条件初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchParamInit( ZKN2_WORK * wk )
{
	wk->search_prm[ZKN2_SEARCH_PRM_ROW]      = ZKN2LIST_SEARCH_DEF_SORT;		// 並び順
	wk->search_prm[ZKN2_SEARCH_PRM_NAME]     = ZKN2LIST_SEARCH_DEF_NAME;		// 名前
	wk->search_prm[ZKN2_SEARCH_PRM_TYPE1]    = ZKN2LIST_SEARCH_DEF_TYPE;		// タイプ１
	wk->search_prm[ZKN2_SEARCH_PRM_TYPE2]    = ZKN2LIST_SEARCH_DEF_TYPE;		// タイプ２
	wk->search_prm[ZKN2_SEARCH_PRM_HEIGHT_L] = 0;								// 高さ（低）
	wk->search_prm[ZKN2_SEARCH_PRM_HEIGHT_H] = ZKN2_HW_DOT_MAX;					// 高さ（高）
	wk->search_prm[ZKN2_SEARCH_PRM_WEIGHT_L] = 0;								// 重さ（低）
	wk->search_prm[ZKN2_SEARCH_PRM_WEIGHT_H] = ZKN2_HW_DOT_MAX;					// 重さ（高）
	wk->search_prm[ZKN2_SEARCH_PRM_AREA]     = ZKN2LIST_SEARCH_DEF_AREA;		// 地域
	wk->search_prm[ZKN2_SEARCH_PRM_FORM]     = ZKN2LIST_SEARCH_DEF_FORM;		// 形
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面メインページのＢＧ初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SearchPageBgLoad( ZKN2_WORK * wk )
{
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UNDER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_S );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_btn01_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UPPER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_list_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_top_m_lz_NSCR,
		wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
//		NARC_zukan_gra_zukan_gs_kensaku_m_NCLR, HEAPID_ZUKAN, FADE_MAIN_BG, 0, 0 );
		NARC_zukan_gra_zukan_gs_m_NCLR, HEAPID_ZUKAN, FADE_MAIN_BG, 0, 0 );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_CENTER_S, 0, 0, TRUE, HEAPID_ZUKAN );
	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );
	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_s_lz_NSCR,
		wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );
	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_window_s_lz_NSCR,
		wk->bgl, ZKN2_BGF_CENTER_S, 0, 0, TRUE, HEAPID_ZUKAN );
	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
//		NARC_zukan_gra_zukan_gs_kensaku_m_NCLR, HEAPID_ZUKAN, FADE_SUB_BG, 0, 0 );
		NARC_zukan_gra_zukan_gs_s_NCLR, HEAPID_ZUKAN, FADE_SUB_BG, 0, 0 );

	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_S );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面各ページの初期化
 *
 * @param	wk		図鑑画面ワーク
 * @param	mode	ページ
 * @param	pos		カーソル位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchInputInit( ZKN2_WORK * wk, u32 mode, u32 pos )
{
	switch( mode ){
	case ZKN2MAIN_SEARCHINIT_MAIN:		// 検索画面・メイン
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_top_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );
		ZKN2UI_SearchMainCursorMoveSet( wk, pos );
		ZKN2BMP_SearchInfoPut( wk, ZKN2BMP_SEARCH_INFO_INIT );
		ZKN2BMP_SearchMainPut( wk );
		ZKN2BMP_SearchParamPut( wk );
		ZKN2OBJ_SearchMode( wk, ZKN2OBJ_SEARCH_MAIN );
		break;

	case ZKN2MAIN_SEARCHINIT_ROW:		// 検索画面・並び順
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_sort_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );
		SearchSelBgChg( wk, &SearchRowSel[wk->search_prm[ZKN2_SEARCH_PRM_ROW]], TRUE );
		ZKN2UI_SearchRowCursorMoveSet( wk );
		ZKN2BMP_SearchInfoPut( wk, ZKN2BMP_SEARCH_INFO_SORT );
		ZKN2BMP_SearchInputRowPut( wk );
		ZKN2OBJ_SearchMode( wk, ZKN2OBJ_SEARCH_NONE );
		break;

	case ZKN2MAIN_SEARCHINIT_NAME:		// 検索画面・名前
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_name02_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );
		SearchNameSelectPos( wk, wk->search_prm[ZKN2_SEARCH_PRM_NAME], TRUE );
		ZKN2UI_SearchNameCursorMoveSet( wk );
		ZKN2BMP_SearchInfoPut( wk, ZKN2BMP_SEARCH_INFO_NAME );
		ZKN2BMP_SearchInputNamePut( wk );
		ZKN2OBJ_SearchMode( wk, ZKN2OBJ_SEARCH_NONE );
		break;

	case ZKN2MAIN_SEARCHINIT_TYPE:		// 検索画面・タイプ
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_type_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );
		ZKN2MAIN_SearchTypeSelect( wk );
		ZKN2UI_SearchTypeCursorMoveSet( wk );
		ZKN2BMP_SearchInfoPut( wk, ZKN2BMP_SEARCH_INFO_TYPE );
		ZKN2BMP_SearchInputTypePut( wk );
		ZKN2OBJ_SearchMode( wk, ZKN2OBJ_SEARCH_NONE );
		break;

	case ZKN2MAIN_SEARCHINIT_HEIGHT:	// 検索画面・高さ
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_takasa_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );
		ZKN2UI_SearchHeightCursorMoveSet( wk );
		ZKN2BMP_SearchInfoPut( wk, ZKN2BMP_SEARCH_INFO_HEIGHT );
		ZKN2BMP_SearchInputHeightPut( wk );
		ZKN2OBJ_SearchMode( wk, ZKN2OBJ_SEARCH_HEIGHT );
		break;

	case ZKN2MAIN_SEARCHINIT_WEIGHT:	// 検索画面・重さ
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_omosa_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );
		ZKN2UI_SearchWeightCursorMoveSet( wk );
		ZKN2BMP_SearchInfoPut( wk, ZKN2BMP_SEARCH_INFO_WEIGHT );
		ZKN2BMP_SearchInputWeightPut( wk );
		ZKN2OBJ_SearchMode( wk, ZKN2OBJ_SEARCH_WEIGHT );
		break;

	case ZKN2MAIN_SEARCHINIT_AREA:		// 検索画面・地域
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_chiiki_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );
		SearchSelBgChg( wk, &SearchAreaSel[wk->search_prm[ZKN2_SEARCH_PRM_AREA]], TRUE );
		ZKN2UI_SearchAreaCursorMoveSet( wk );
		ZKN2BMP_SearchInfoPut( wk, ZKN2BMP_SEARCH_INFO_AREA );
		ZKN2BMP_SearchInputAreaPut( wk );
		ZKN2OBJ_SearchMode( wk, ZKN2OBJ_SEARCH_NONE );
		SearchAreaZenkokuSet( wk );
		break;

	case ZKN2MAIN_SEARCHINIT_FORM:		// 検索画面・形
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_kensaku_katachi_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_CENTER_M, 0, 0, TRUE, HEAPID_ZUKAN );
		SearchFormSelectPos( wk, wk->search_prm[ZKN2_SEARCH_PRM_FORM], TRUE );
		ZKN2UI_SearchFormCursorMoveSet( wk );
		ZKN2BMP_SearchInfoPut( wk, ZKN2BMP_SEARCH_INFO_FORM );
		ZKN2BMP_SearchInputFormPut( wk );
		ZKN2OBJ_SearchMode( wk, ZKN2OBJ_SEARCH_FORM );
		break;
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面ボタン切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	sel		ボタン位置データ
 * @param	flg		選択フラグ ( TRUE = ON, FALSE = OFF )
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SearchSelBgChg( ZKN2_WORK * wk, const ZKN2MAIN_SEARCH_BG_SEL * sel, BOOL flg )
{
	if( flg == TRUE ){
		GF_BGL_ScrPalChange( wk->bgl, ZKN2_BGF_CENTER_M, sel->px, sel->py, sel->sx, sel->sy, 3 );
	}else{
		GF_BGL_ScrPalChange( wk->bgl, ZKN2_BGF_CENTER_M, sel->px, sel->py, sel->sx, sel->sy, 2 );
	}
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_M );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面選択ボタン切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	sel		ボタン位置データ
 * @param	prm		現在の選択位置
 * @param	num		新しい選択位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SearchSelect( ZKN2_WORK * wk, const ZKN2MAIN_SEARCH_BG_SEL * sel, u32 * prm, u32 num )
{
	SearchSelBgChg( wk, &sel[*prm], FALSE );
	*prm = num;
	SearchSelBgChg( wk, &sel[*prm], TRUE );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面並び順選択切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	num		選択位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchRowSelect( ZKN2_WORK * wk, u32 num )
{
	SearchSelect( wk, SearchRowSel, &wk->search_prm[ZKN2_SEARCH_PRM_ROW], num );
	ZKN2BMP_SearchSelectRowPut( wk, ZKN2_BMPWIN_SEARCH_ROW_MODE );
	GF_BGL_BmpWinOnVReq( &wk->win[ZKN2_BMPWIN_SEARCH_ROW_MODE] );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面タイプ選択切り替え
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchTypeSelect( ZKN2_WORK * wk )
{
	u32	i;

	for( i=0; i<NELEMS(SearchTypeSel); i++ ){
		SearchSelBgChg( wk, &SearchTypeSel[i], FALSE );
	}
	SearchSelBgChg( wk, &SearchTypeSel[wk->search_prm[ZKN2_SEARCH_PRM_TYPE1]], TRUE );
	SearchSelBgChg( wk, &SearchTypeSel[wk->search_prm[ZKN2_SEARCH_PRM_TYPE2]], TRUE );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面地域選択切り替え
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchAreaSelect( ZKN2_WORK * wk, u32 num )
{
	SearchSelect( wk, SearchAreaSel, &wk->search_prm[ZKN2_SEARCH_PRM_AREA], num );
	ZKN2BMP_SearchSelectAreaPut( wk, ZKN2_BMPWIN_SEARCH_AREA_SEL );
	GF_BGL_BmpWinOnVReq( &wk->win[ZKN2_BMPWIN_SEARCH_AREA_SEL] );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面地域ページのボタン表示変更
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 *
 *	全国図鑑オープンかどうかで変更する
 */
//--------------------------------------------------------------------------------------------
static void SearchAreaZenkokuSet( ZKN2_WORK * wk )
{
	const ZKN2MAIN_SEARCH_BG_SEL * sel;
	u16 * scrn;

	if( wk->zenkoku_mode == TRUE ){ return; }

	CURSORMOVE_MoveTableBitOff( wk->cmwk, ZKN2UI_SEARCH_AREA_KANTO );

	// ボタンをボタンの上のスクリーンデータで書き換える（ボタンの影も）
	sel  = &SearchAreaSel[ZKN2UI_SEARCH_AREA_KANTO];
	scrn = GF_BGL_ScreenAdrsGet( wk->bgl, ZKN2_BGF_CENTER_M );
	MI_CpuCopy16( &scrn[(sel->py-2)*32+(sel->px-1)], &scrn[(sel->py-1)*32+(sel->px-1)], (sel->sx+2)*2 );
	MI_CpuCopy16( &scrn[(sel->py-2)*32+(sel->px-1)], &scrn[(sel->py+0)*32+(sel->px-1)], (sel->sx+2)*2 );
	MI_CpuCopy16( &scrn[(sel->py-2)*32+(sel->px-1)], &scrn[(sel->py+1)*32+(sel->px-1)], (sel->sx+2)*2 );
	MI_CpuCopy16( &scrn[(sel->py-3)*32+(sel->px-1)], &scrn[(sel->py+2)*32+(sel->px-1)], (sel->sx+2)*2 );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_M );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面姿選択ボタン切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	pos		選択位置
 * @param	flg		選択フラグ ( TRUE = ON, FALSE = OFF )
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SearchFormSelectPos( ZKN2_WORK * wk, u32 pos, BOOL flg )
{
	ZKN2MAIN_SEARCH_BG_SEL	sel;

	sel.sx = SEARCH_FORM_SX;
	sel.sy = SEARCH_FORM_SY;

	sel.px = SEARCH_FORM_PX + pos % SEARCH_FORM_X_MAX * SEARCH_FORM_SPACE_X;
	sel.py = SEARCH_FORM_PY + pos / SEARCH_FORM_X_MAX * SEARCH_FORM_SPACE_Y;

	SearchSelBgChg( wk, &sel, flg );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面姿選択切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	num		選択位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchFormSelect( ZKN2_WORK * wk, u32 num )
{
	SearchFormSelectPos( wk, wk->search_prm[ZKN2_SEARCH_PRM_FORM], FALSE );
	wk->search_prm[ZKN2_SEARCH_PRM_FORM] = num;
	SearchFormSelectPos( wk, wk->search_prm[ZKN2_SEARCH_PRM_FORM], TRUE );

	ZKN2OBJ_MainFormSet( wk );
}


//--------------------------------------------------------------------------------------------
/**
 * 検索画面：名前番号取得
 *
 * @param	num		選択位置
 *
 * @return	名前番号
 */
//--------------------------------------------------------------------------------------------
u32 ZKN2MAIN_SearchNamePutNumGet( u32 num )
{
	return SearchNamePosTbl[num];
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面名前選択ボタン切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	pos		選択位置
 * @param	flg		選択フラグ ( TRUE = ON, FALSE = OFF )
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SearchNameSelectPos( ZKN2_WORK * wk, u32 pos, BOOL flg )
{
	ZKN2MAIN_SEARCH_BG_SEL	sel;

	sel.sx = SEARCH_NAME_SX;
	sel.sy = SEARCH_NAME_SY;

	sel.px = SEARCH_NAME_PX + SearchNamePosTbl[pos] / SEARCH_NAME_Y_MAX * SEARCH_NAME_SPACE_X;
	sel.py = SEARCH_NAME_PY + SearchNamePosTbl[pos] % SEARCH_NAME_Y_MAX * SEARCH_NAME_SPACE_Y;

	SearchSelBgChg( wk, &sel, flg );
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面名前選択切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	num		選択位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchNameSelect( ZKN2_WORK * wk, u32 num )
{
	SearchNameSelectPos( wk, wk->search_prm[ZKN2_SEARCH_PRM_NAME], FALSE );
	wk->search_prm[ZKN2_SEARCH_PRM_NAME] = num;
	SearchNameSelectPos( wk, wk->search_prm[ZKN2_SEARCH_PRM_NAME], TRUE );

	ZKN2BMP_SearchSelectNamePut( wk, ZKN2_BMPWIN_SEARCH_NAME_SEL );
	GF_BGL_BmpWinOnVReq( &wk->win[ZKN2_BMPWIN_SEARCH_NAME_SEL] );
}

//--------------------------------------------------------------------------------------------
/**
 * カバーのBGWINフレーム作成
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_ListCoverBGWFSet( ZKN2_WORK * wk )
{
	NNSG2dScreenData * scrn;
	void * buf;
	u16 * cv;
	u16 * hd;
	u16 * raw;
	u16	sx, sy;
	u32	i, j;

	cv = BGWINFRM_FrameBufGet( wk->wfrm, ZKN2_BGWF_SEARCH_COVER_D );
	hd = BGWINFRM_FrameBufGet( wk->wfrm, ZKN2_BGWF_SEARCH_COVER_H );

	buf = ArcUtil_HDL_ScrnDataGet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_top_m_lz_NSCR, TRUE, &scrn, HEAPID_ZUKAN );
	raw = (u16 *)scrn->rawData;

	for( i=0; i<24; i++ ){
		memcpy( &cv[i*32], &raw[i*32], sizeof(u16)*32 );
		memcpy( &hd[i*3], &raw[32*32+i*32], sizeof(u16)*3 );
	}

	sys_FreeMemoryEz( buf );

	if( wk->zenkoku_mode == FALSE ){
		for( i=0; i<COVER_SWITCH_SY; i++ ){
			for( j=0; j<COVER_SWITCH_SX; j++ ){
				raw = &cv[(i+COVER_SWITCH_PY)*32 + COVER_SWITCH_PX+j];
				*raw = ( (*raw) & 0xf000 ) | COVER_NULL_CHAR;
			}
		}
	}

	if( wk->zkn_mode == ZKN2_MODE_JOHTO ){
		hd = BGWINFRM_FrameBufGet( wk->wfrm, ZKN2_BGWF_LOGO_JOHTO );
		BGWINFRM_SizeGet( wk->wfrm, ZKN2_BGWF_LOGO_JOHTO, &sx, &sy );
		for( i=0; i<sy; i++ ){
			for( j=0; j<sx; j++ ){
				cv[(i+BGWF_LOGO_JOHTO_PY)*32 + BGWF_LOGO_JOHTO_PX+j] = hd[i*sx+j];
			}
		}
	}else{
		hd = BGWINFRM_FrameBufGet( wk->wfrm, ZKN2_BGWF_LOGO_ZENKOKU );
		BGWINFRM_SizeGet( wk->wfrm, ZKN2_BGWF_LOGO_JOHTO, &sx, &sy );
		for( i=0; i<sy; i++ ){
			for( j=0; j<sx; j++ ){
				cv[(i+BGWF_LOGO_ZENKOKU_PY)*32 + BGWF_LOGO_ZENKOKU_PX+j] = hd[i*sx+j];
			}
		}
	}

	ZKN2BMP_SearchCoverStrPut( wk );
}


//--------------------------------------------------------------------------------------------
/**
 * 検索ページ：選択ポケモン情報表示
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchSelPosInfoPut( ZKN2_WORK * wk )
{
	u32	pos;
	u16	mons;

	pos = ZKN2LIST_SelPosGet( wk );

	if( pos == 0 ){
		ZKN2OBJ_LangArrowVanish( wk, ZKN2_OBJ_SEARCH_ARROW_L, FALSE );
		ZKN2OBJ_ListLangVanish( wk, ZKN2_OBJ_SEARCH_LANGICON_M, FALSE );
		ZKN2OBJ_SearchPageListVanish( wk, FALSE );
		ZKN2BMP_ListLabelPokeNamePut( wk, 0, ZKN2_BMPWIN_SEARCH_LABEL_POKE );
		ZKN2BMP_SearchPokeInfoVanish( wk );
		ZKN2BMP_SearchInfoVanish( wk, TRUE );
		GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_S );
		wk->search_pri_flg = 1;
		return;
	}

	ZKN2BMP_SearchInfoVanish( wk, FALSE );

//	mons = ZKN2LIST_SearchSelMonsGet( wk );
	mons = ZKN2LIST_SelMonsGet( wk );

	if( ZKN2MAIN_LangCheck( wk, mons, wk->lang ) == FALSE ){
		wk->lang = PM_LANG;
	}

	// BMP
	ZKN2BMP_ListLabelPokeNamePut( wk, mons, ZKN2_BMPWIN_SEARCH_LABEL_POKE );
	ZKN2BMP_SearchListPokeInfoPut( wk, mons, pos );
	ZKN2BMP_SearchListPokeTextPut( wk, mons, pos );

	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_S );
	wk->search_pri_flg = 2;

	// OBJ
	ZKN2OBJ_SearchPageListVanish( wk, TRUE );
	// ポケモングラフィック
	ZKN2OBJ_PokeGraChange( wk, mons, ZKN2_OBJ_SEARCH_POKEGRA, ZKN2_OBJ_SEARCH_NAZOPOKE_S );
	// 言語アイコン
	ZKN2OBJ_ListMainLangIconChg( wk, mons, ZKN2_OBJ_SEARCH_LANGICON_M );
	ZKN2OBJ_ListSubLangIconChg( wk, mons, ZKN2_OBJ_SEARCH_LANGICON1 );
	// タイプアイコン
	ZKN2OBJ_TypeIconAnmChg( wk, mons, pos, ZKN2_OBJ_SEARCH_TYPEICON1 );
	// 足跡
	ZKN2OBJ_PokeFootChange( wk, mons, pos, ZKN2_OBJ_SEARCH_POKEFOOT );
	// ボール
	ZKN2OBJ_ListBallPut( wk, pos, ZKN2_OBJ_SEARCH_BALL_S );

	// 空き番号のときの処理
	if( mons == 0 ){
		ZKN2OBJ_LangArrowVanish( wk, ZKN2_OBJ_SEARCH_ARROW_L, FALSE );
		ZKN2OBJ_ListLangVanish( wk, ZKN2_OBJ_SEARCH_LANGICON_M, FALSE );
		ZKN2MAIN_PokeInfoBgPutMax( wk->bgl, ZKN2_BGF_UNDER_S, wk->graphic_ah, HEAPID_ZUKAN );
		GF_BGL_BmpWinOffVReq( &wk->win[ZKN2_BMPWIN_SEARCH_TITLE] );
		ZKN2OBJ_Vanish( wk, ZKN2_OBJ_SEARCH_NAZOPOKE_S, FALSE );
	}else{
		if( ZKN2MAIN_LangChangeCheck( wk, mons ) == TRUE ){
			ZKN2OBJ_LangArrowVanish( wk, ZKN2_OBJ_SEARCH_ARROW_L, TRUE );
		}else{
			ZKN2OBJ_LangArrowVanish( wk, ZKN2_OBJ_SEARCH_ARROW_L, FALSE );
		}
		ZKN2OBJ_ListLangVanish( wk, ZKN2_OBJ_SEARCH_LANGICON_M, TRUE );
		ZKN2MAIN_PokeInfoBgPut( wk->bgl, ZKN2_BGF_UNDER_S, wk->lang, wk->graphic_ah, HEAPID_ZUKAN );
		GF_BGL_BmpWinOnVReq( &wk->win[ZKN2_BMPWIN_SEARCH_TITLE] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 検索画面リスト表示時のＢＧプライオリティ変更
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 *
 *	普通に変更すると即反映されるため、VBLANKで変更してます
 */
//--------------------------------------------------------------------------------------------
static void SearchListBgPriorityChange( ZKN2_WORK * wk )
{
	switch( wk->search_pri_flg ){
	case 0:
		return;
	case 1:			// 検索情報
		GF_BGL_PrioritySet( ZKN2_BGF_CENTER_S, 2 );
		GF_BGL_PrioritySet( ZKN2_BGF_UNDER_S, 3 );
		break;
	case 2:			// ポケモン情報
		GF_BGL_PrioritySet( ZKN2_BGF_CENTER_S, 3 );
		GF_BGL_PrioritySet( ZKN2_BGF_UNDER_S, 2 );
	}
	wk->search_pri_flg = 0;
}


//--------------------------------------------------------------------------------------------
/**
 * 検索ページ：言語切り替え
 *
 * @param	wk		図鑑画面ワーク
 * @param	mons	ポケモン番号
 * @param	mv		切り替え方向
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchLangChange( ZKN2_WORK * wk, u16 mons, s16 mv )
{
	u32	pos;
	u32	i;
	s16	lang_t, lang_c;

	if( ZukanWork_GetTextVersionUpMasterFlag(wk->dat->zukan_work) == FALSE ){
		return;
	}

	pos = ZKN2LIST_SelPosGet( wk );
	if( pos == 0 ){
		return;
	}

	lang_t = ZKN_WT_GetLANG_Code_ZKN_WORLD_TEXT_Code( wk->lang );

	for( i=0; i<ZKN_WORLD_TEXT_NUM; i++ ){
		lang_t += mv;
		if( lang_t < ZKN_WORLD_TEXT_JAPAN ){
			lang_t = ZKN_WORLD_TEXT_SPA;
		}else if( lang_t >= ZKN_WORLD_TEXT_NUM ){
			lang_t = ZKN_WORLD_TEXT_JAPAN;
		}
		lang_c = ZKN_WT_GetZKN_WORLD_TEXT_Code_LANG_Code( lang_t );
		if( lang_c == wk->lang ){
			break;
		}
		if( ZKN2MAIN_LangCheck( wk, mons, lang_c ) == TRUE || lang_c == PM_LANG ){
			wk->lang = lang_c;
			// 言語表示切り替え
			ZKN2BMP_ListLabelPokeNamePut( wk, mons, ZKN2_BMPWIN_SEARCH_LABEL_POKE );
			// 上画面表示切り替え
			ZKN2MAIN_PokeInfoBgPut( wk->bgl, ZKN2_BGF_UNDER_S, wk->lang, wk->graphic_ah, HEAPID_ZUKAN );
			ZKN2BMP_SearchListPokeTextPut( wk, mons, pos );
			// 言語アイコン
			ZKN2OBJ_ListMainLangIconChg( wk, mons, ZKN2_OBJ_SEARCH_LANGICON_M );
			ZKN2OBJ_ListSubLangIconChg( wk, mons, ZKN2_OBJ_SEARCH_LANGICON1 );
			// タイプアイコン
			ZKN2OBJ_TypeIconAnmChg( wk, mons, pos, ZKN2_OBJ_SEARCH_TYPEICON1 );
			// 足跡
			ZKN2OBJ_PokeFootChange( wk, mons, pos, ZKN2_OBJ_SEARCH_POKEFOOT );
			// ボール
			ZKN2OBJ_ListBallPut( wk, pos, ZKN2_OBJ_SEARCH_BALL_S );

			Snd_SePlay( SE_ZKN2_SELECT );
			break;
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 検索結果表示デモ時のサブ画面のマスク処理
 *
 * @param	wk		図鑑画面ワーク
 * @param	flg		フラグ ( TRUE = マスク有効 )
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_SearchSubWindowMask( BOOL flg )
{
	if( flg == TRUE ){
		GXS_SetVisibleWnd( GX_WNDMASK_W0 );
		G2S_SetWnd0InsidePlane(
			GX_WND_PLANEMASK_BG0 | GX_WND_PLANEMASK_BG1 |
			GX_WND_PLANEMASK_BG2 | GX_WND_PLANEMASK_BG3, TRUE );
		G2S_SetWndOutsidePlane(
			GX_WND_PLANEMASK_BG0 | GX_WND_PLANEMASK_BG1 |
			GX_WND_PLANEMASK_BG2 | GX_WND_PLANEMASK_BG3 | GX_WND_PLANEMASK_OBJ, TRUE );
		G2S_SetWnd0Position( 0, 152, 255, 192 );
	}else{
		GXS_SetVisibleWnd( GX_WNDMASK_NONE );
	}
}


//============================================================================================
/*
	詳細
*/
//============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面分布ページのＢＧ初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PlacePageBgLoad( ZKN2_WORK * wk )
{
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_M );
//	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_M );
//	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_S );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_bunpu_m_lz_NSCR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	if( wk->zenkoku_mode == TRUE ){
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_bunpu02_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_COVER_M, 0, 0, TRUE, HEAPID_ZUKAN );
	}else{
		ArcUtil_HDL_ScrnSet(
			wk->graphic_ah, NARC_zukan_gra_zukan_gs_bunpu01_m_lz_NSCR,
			wk->bgl, ZKN2_BGF_COVER_M, 0, 0, TRUE, HEAPID_ZUKAN );
	}

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_bunpu_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_COVER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_bunpu_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_btn01_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UPPER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
		NARC_zukan_gra_zukan_gs_m_NCLR, HEAPID_ZUKAN, FADE_MAIN_BG, 0, 0 );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_bunpu_s_lz_NSCR,
		wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_bunpu_s_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_map_s_lz_NSCR,
		wk->bgl, ZKN2_BGF_COVER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_map_s_lz_NCGR,
		wk->bgl, ZKN2_BGF_COVER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
		NARC_zukan_gra_zukan_gs_s_NCLR, HEAPID_ZUKAN, FADE_SUB_BG, 0, 0 );

	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_S );
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面大きさページのＢＧ初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SizePageBgLoad( ZKN2_WORK * wk )
{
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_S );
//	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UNDER_S );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_omosa_m_lz_NSCR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_omosa_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_btn01_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UPPER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
		NARC_zukan_gra_zukan_gs_m_NCLR, HEAPID_ZUKAN, FADE_MAIN_BG, 0, 0 );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_okisa_s_lz_NSCR,
		wk->bgl, ZKN2_BGF_CENTER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_okisa_s_lz_NCGR,
		wk->bgl, ZKN2_BGF_CENTER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
		NARC_zukan_gra_zukan_gs_s_NCLR, HEAPID_ZUKAN, FADE_SUB_BG, 0, 0 );

	BGWINFRM_FramePut(
		wk->wfrm, ZKN2_BGWF_BTN_DETAIL, BGWF_BTN_DETAIL_PX, BGWF_BTN_DETAIL_PY );

	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_S );
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面「戻る」ページのＢＧ初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void DetailRetPageBgLoad( ZKN2_WORK * wk )
{
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_M );
//	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UNDER_S );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_modoru_m_lz_NSCR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_modoru_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_btn01_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UPPER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
		NARC_zukan_gra_zukan_gs_m_NCLR, HEAPID_ZUKAN, FADE_MAIN_BG, 0, 0 );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_modoru_s_lz_NSCR,
		wk->bgl, ZKN2_BGF_CENTER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_modoru_s_lz_NCGR,
		wk->bgl, ZKN2_BGF_CENTER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
		NARC_zukan_gra_zukan_gs_s_NCLR, HEAPID_ZUKAN, FADE_SUB_BG, 0, 0 );

	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_S );
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面姿ページ１のＢＧ初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_FormPageBgLoad( ZKN2_WORK * wk )
{
//	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_M );
//	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_S );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_S );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata11_m_lz_NSCR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata01_m_lz_NSCR,
		wk->bgl, ZKN2_BGF_COVER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_COVER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_btn01_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UPPER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
		NARC_zukan_gra_zukan_gs_m_NCLR, HEAPID_ZUKAN, FADE_MAIN_BG, 0, 0 );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata01_s_lz_NSCR,
		wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata_s_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	PaletteWorkSet_ArcHandle(
		wk->pfd, wk->graphic_ah,
		NARC_zukan_gra_zukan_gs_s_NCLR, HEAPID_ZUKAN, FADE_SUB_BG, 0, 0 );

	if( wk->detail_form_max == 1 ){
		NNSG2dScreenData * scrn;
		void * buf;

		buf = ArcUtil_HDL_ScrnDataGet(
				wk->graphic_ah, NARC_zukan_gra_form_btn_vanish_lz_NSCR, TRUE, &scrn, HEAPID_ZUKAN );

		GF_BGL_ScrWrite(
			wk->bgl, ZKN2_BGF_COVER_M, scrn->rawData, 16, 16, 16, 4 );

		sys_FreeMemoryEz( buf );
	}

	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_S );
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面姿ページ２のＢＧ初期化
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_Form2BgLoad( ZKN2_WORK * wk )
{
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_M );
	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_M );

//	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_COVER_S );
//	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_UPPER_S );
//	ZKN2MAIN_BgScrClear( wk, ZKN2_BGF_CENTER_S );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata02_m_lz_NSCR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata_m_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_M, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_ScrnSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata02_s_lz_NSCR,
		wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	ArcUtil_HDL_BgCharSet(
		wk->graphic_ah, NARC_zukan_gra_zukan_gs_sugata_s_lz_NCGR,
		wk->bgl, ZKN2_BGF_UNDER_S, 0, 0, TRUE, HEAPID_ZUKAN );

	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_M );
//	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_M );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_M );
//	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_COVER_S );
//	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UPPER_S );
//	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_CENTER_S );
	GF_BGL_LoadScreenV_Req( wk->bgl, ZKN2_BGF_UNDER_S );
}

//--------------------------------------------------------------------------------------------
/**
 * 詳細画面フォルムリスト作成
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_DetailFormTblMake( ZKN2_WORK * wk )
{
	u32	i;

	memset( wk->detail_form, ZKN2MAIN_FORM_NONE, ZKN2MAIN_DETAIL_FORM_SIZE );

	switch( wk->detail_mons ){
	case MONSNO_ANNOON:		// アンノーン
	case MONSNO_SIIUSI:		// シーウシ（カラナクシ）
	case MONSNO_SIIDORUGO:	// シードルゴ（トリトドン）
	case MONSNO_MINOMUTTI:	// ミノムッチ
	case MONSNO_MINOMESU:	// ミノメス（ミノマダム）
	case MONSNO_DEOKISISU:	// デオキシス
	case MONSNO_EURISU:		// シェイミ
	case MONSNO_KIMAIRAN:	// ギラティナ
	case MONSNO_PURAZUMA:	// ロトム
	case MONSNO_PITYUU:		// ピチュー
		wk->detail_form_max = ZukanWork_GetPokeFormNum(wk->dat->zukan_work,wk->detail_mons);
		for( i=0; i<wk->detail_form_max; i++ ){
			u32 frm = ZukanWork_GetPokeForm( wk->dat->zukan_work, wk->detail_mons, i );
			wk->detail_form[i] = ZKN2MAIN_FORM_EXTRA | frm;
		}
		break;

	case MONSNO_POWARUN:	// ポワルン
		wk->detail_form_max = ZUKAN_WORK_POWARUN_FORM_NUM;
		for( i=0; i<wk->detail_form_max; i++ ){
			wk->detail_form[i] = ZKN2MAIN_FORM_EXTRA | i;
		}
		break;

	case MONSNO_THERISYU:	// チェリム
		wk->detail_form_max = ZUKAN_WORK_CHERIMU_FORM_NUM;
		for( i=0; i<wk->detail_form_max; i++ ){
			wk->detail_form[i] = ZKN2MAIN_FORM_EXTRA | i;
		}
		break;

	default:
		wk->detail_form[0] = SexFormGet( wk, ZUKAN_WORK_SEX_FIRST );
		wk->detail_form[1] = SexFormGet( wk, ZUKAN_WORK_SEX_SECOND );
		if( wk->detail_form[1] == ZKN2MAIN_FORM_NONE ){
			wk->detail_form_max = 1;
		}else{
			wk->detail_form_max = 2;
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 見た順の性別取得
 *
 * @param	wk		図鑑画面ワーク
 * @param	flg		見た順
 *
 * @return	性別
 */
//--------------------------------------------------------------------------------------------
static u8 SexFormGet( ZKN2_WORK * wk, int flg )
{
	switch( ZukanWork_GetPokeSexFlag(wk->dat->zukan_work,wk->detail_mons,flg) ){
	case PARA_MALE:		// ♂
		return ZKN2MAIN_FORM_MALE;
	case PARA_FEMALE:	// ♀
		return ZKN2MAIN_FORM_FAMALE;
	case PARA_UNK:		// 不明
		return ZKN2MAIN_FORM_SEX_UNKNOWN;
	default:
		if( flg == ZUKAN_WORK_SEX_FIRST ){
			return ZKN2MAIN_FORM_SEX_UNKNOWN;
		}
	}
	return ZKN2MAIN_FORM_NONE;
}


//--------------------------------------------------------------------------------------------
/**
 * 高さ・重さデータ読み込み
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_HeightWeightLoad( ZKN2_WORK * wk )
{
	ARCHANDLE * ah;
	ZKN2_SIZE_WORK * siz;
	int * hb;
	int * wb;
	u32	i;

	siz = &wk->size_work;

	ah = ArchiveDataHandleOpen( ZKN_GIRA_GetZukanDataArcIdx(), HEAPID_ZUKAN );

	if( MyStatus_GetMySex( wk->dat->myst ) == 0 ){
		siz->myPos = ArcUtil_HDL_Load(
						ah, NARC_zukan_data_zkn_height_y_man_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );
		siz->myScale = ArcUtil_HDL_Load(
						ah, NARC_zukan_data_zkn_height_scale_man_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );
		siz->pokePos = ArcUtil_HDL_Load(
						ah, NARC_zukan_data_zkn_height_y_man_poke_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );
		siz->pokeScale = ArcUtil_HDL_Load(
							ah, NARC_zukan_data_zkn_height_scale_man_poke_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );
	}else{
		siz->myPos = ArcUtil_HDL_Load(
						ah, NARC_zukan_data_zkn_height_y_girl_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );
		siz->myScale = ArcUtil_HDL_Load(
						ah, NARC_zukan_data_zkn_height_scale_girl_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );
		siz->pokePos = ArcUtil_HDL_Load(
						ah, NARC_zukan_data_zkn_height_y_girl_poke_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );
		siz->pokeScale = ArcUtil_HDL_Load(
							ah, NARC_zukan_data_zkn_height_scale_girl_poke_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );
	}

	// ポケモン高さ
	wk->mons_height = ArcUtil_HDL_Load( ah, NARC_zukan_data_zkn_height_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );
	// ポケモン重さ
	wk->mons_weight = ArcUtil_HDL_Load( ah, NARC_zukan_data_zkn_gram_dat, FALSE, HEAPID_ZUKAN, ALLOC_TOP );

	ArchiveDataHandleClose( ah );
}

//--------------------------------------------------------------------------------------------
/**
 * 高さ・重さデータ解放
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_HeightWeightFree( ZKN2_WORK * wk )
{
	ZKN2_SIZE_WORK * siz = &wk->size_work;

	sys_FreeMemoryEz( wk->mons_height );
	sys_FreeMemoryEz( wk->mons_weight );

	sys_FreeMemoryEz( siz->myPos );
	sys_FreeMemoryEz( siz->myScale );
	sys_FreeMemoryEz( siz->pokePos );
	sys_FreeMemoryEz( siz->pokeScale );
}

//--------------------------------------------------------------------------------------------
/**
 * 分布データ作成
 *
 * @param	wk		図鑑画面ワーク
 * @param	time	時間帯
 * @param	mode	地域 ( 0 = ジョウト, 1 = カントー )
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_EncountDataLoad( ZKN2_WORK * wk, u32 time, u32 mode )
{
	u32	siz;
	u32	fld_max;

	EncountDataLoad( &wk->enc_data.fld, wk->detail_mons, ZKN2_ENC_FLD_MORNING + time );
	EncountDataLoad( &wk->enc_data.fld_sp, wk->detail_mons, ZKN2_ENC_FLD_SPECIAL );
	EncountDataLoad( &wk->enc_data.dan, wk->detail_mons, ZKN2_ENC_DAN_MORNING + time );
	EncountDataLoad( &wk->enc_data.dan_sp, wk->detail_mons, ZKN2_ENC_DAN_SPECIAL );

	siz = 1;									//「ぜんいき」分
	siz += ( wk->enc_data.fld.num - 1 );
	siz += ( wk->enc_data.fld_sp.num - 1 );
	siz += ( wk->enc_data.dan.num - 1 );
	siz += ( wk->enc_data.dan_sp.num - 1 );

	// リスト作成
	wk->enc_data.all.map  = sys_AllocMemory( HEAPID_ZUKAN, sizeof(s32)*siz );
	wk->enc_data.all_type = sys_AllocMemory( HEAPID_ZUKAN, sizeof(u32)*siz );
	MI_CpuClear32( wk->enc_data.all.map, sizeof(s32)*siz );
	MI_CpuClear32( wk->enc_data.all_type, sizeof(s32)*siz );

	wk->enc_data.all.map[0] = ZKN2_ENC_ALL_AREA;	//「ぜんいき」
	wk->enc_data.all.num = 1;
	wk->enc_data.all_type[0] = 0;

	FldEncDataModeGet( wk, &wk->enc_data.fld, mode, 0 );
	FldEncDataModeGet( wk, &wk->enc_data.fld_sp, mode, 1 );

	fld_max = wk->enc_data.all.num;		// ダンジョンはここからチェックする
	DanEncDataModeGet( wk, &wk->enc_data.dan, mode, fld_max, 0 );
	DanEncDataModeGet( wk, &wk->enc_data.dan_sp, mode, fld_max, 1 );

	EncListSort( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * 分布データ解放
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_EncountDataFree( ZKN2_WORK * wk )
{
	sys_FreeMemoryEz( wk->enc_data.fld.map );
	sys_FreeMemoryEz( wk->enc_data.fld_sp.map );
	sys_FreeMemoryEz( wk->enc_data.dan.map );
	sys_FreeMemoryEz( wk->enc_data.dan_sp.map );
	sys_FreeMemoryEz( wk->enc_data.all.map );

	sys_FreeMemoryEz( wk->enc_data.all_type );
}

//--------------------------------------------------------------------------------------------
/**
 * 分布データ読み込み
 *
 * @param	enc		分布データ作成場所
 * @param	mons	ポケモン番号
 * @param	type	データタイプ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void EncountDataLoad( ZKN2_ENCOUNT_MAP * enc, u32 mons, u32 type )
{
	int arc;
	u32 siz;

	switch( type ){
	// ダンジョン分布データ
	case ZKN2_ENC_DAN_MORNING:
		arc = ZKN_RANGEDATA_DAN_MORNING_ARC_S;
		break;
	case ZKN2_ENC_DAN_NOON:
		arc = ZKN_RANGEDATA_DAN_NOON_ARC_S;
		break;
	case ZKN2_ENC_DAN_NIGHT:
		arc = ZKN_RANGEDATA_DAN_NIGHT_ARC_S;
		break;
	case ZKN2_ENC_DAN_SPECIAL:
		arc = ZKN_RANGEDATA_DAN_SPECIAL_ARC_S;
		break;

	// フィールド分布データ
	case ZKN2_ENC_FLD_MORNING:
		arc = ZKN_RANGEDATA_FLD_MORNING_ARC_S;
		break;
	case ZKN2_ENC_FLD_NOON:
		arc = ZKN_RANGEDATA_FLD_NOON_ARC_S;
		break;
	case ZKN2_ENC_FLD_NIGHT:
		arc = ZKN_RANGEDATA_FLD_NIGHT_ARC_S;
		break;
	case ZKN2_ENC_FLD_SPECIAL:
		arc = ZKN_RANGEDATA_FLD_SPECIAL_ARC_S;
		break;
	}

	enc->map = (s32 *)ArcUtil_LoadEx( ARC_ZUKAN_ENC, arc+mons, FALSE, HEAPID_ZUKAN, ALLOC_TOP, &siz );
	enc->num = siz / sizeof(s32);
}

//--------------------------------------------------------------------------------------------
/**
 * 地域ごとのフィールド分布データを作成
 *
 * @param	wk		図鑑画面ワーク
 * @param	enc		分布データ
 * @param	mode	地域 ( 0 = ジョウト, 1 = カントー )
 * @param	type	データタイプ ( 0 = 通常, 1 = 特殊 )
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void FldEncDataModeGet( ZKN2_WORK * wk, ZKN2_ENCOUNT_MAP * dat, u32 mode, u32 type )
{
	u16	i, j;

	// ジョウト
	if( mode == 0 ){
		for( i=0; i<dat->num-1; i++ ){
			if( wk->fld_grid[dat->map[i]].gridx >= ENC_MAP_AREA_GRID_X ){
				continue;
			}
			for( j=0; j<wk->enc_data.all.num; j++ ){
				if( wk->enc_data.all.map[j] == dat->map[i] ){
					wk->enc_data.all_type[j] |= (1<<type);
					break;
				}
			}
			if( j == wk->enc_data.all.num ){
				wk->enc_data.all.map[wk->enc_data.all.num]  = dat->map[i];
				wk->enc_data.all_type[wk->enc_data.all.num] = (1<<type);
				wk->enc_data.all.num++;
			}
		}
	// カントー
	}else{
		u32	map;
		for( i=0; i<dat->num-1; i++ ){
			map = dat->map[i];
			if( wk->fld_grid[map].gridx < ENC_MAP_AREA_GRID_X ){
				continue;
			}
			if( ZKN2MAIN_ZoneIDRoad2Check( map ) == TRUE ){
				map = ZKN2MAIN_ZoneIDRoad2PosGet();
			}else if( ZKN2MAIN_ZoneIDRoad16Check( map ) == TRUE ){
				map = ZKN2MAIN_ZoneIDRoad16PosGet();
			}
			for( j=0; j<wk->enc_data.all.num; j++ ){
				if( wk->enc_data.all.map[j] == map ){
					wk->enc_data.all_type[j] |= (1<<type);
					break;
				}
			}
			if( j == wk->enc_data.all.num ){
				wk->enc_data.all.map[wk->enc_data.all.num]  = map;
				wk->enc_data.all_type[wk->enc_data.all.num] = (1<<type);
				wk->enc_data.all.num++;
			}
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 地域ごとのダンジョン分布データを作成
 *
 * @param	wk		図鑑画面ワーク
 * @param	enc		分布データ
 * @param	mode	地域 ( 0 = ジョウト, 1 = カントー )
 * @param	start	データ格納開始位置（フィールド分布の最後）
 * @param	type	データタイプ ( 0 = 通常, 1 = 特殊 )
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void DanEncDataModeGet( ZKN2_WORK * wk, ZKN2_ENCOUNT_MAP * dat, u32 mode, u32 start, u32 type )
{
	u16	i, j;

	if( mode == 0 ){
		for( i=0; i<dat->num-1; i++ ){
			if( wk->dan_grid[dat->map[i]].gridx >= ENC_MAP_AREA_GRID_X ){
				continue;
			}
			for( j=start; j<wk->enc_data.all.num; j++ ){
				if( wk->enc_data.all.map[j] == dat->map[i] ){
					wk->enc_data.all_type[j] |= (1<<type);
					break;
				}
			}
			if( j == wk->enc_data.all.num ){
				wk->enc_data.all.map[wk->enc_data.all.num]  = dat->map[i];
				wk->enc_data.all_type[wk->enc_data.all.num] = ENC_MAP_TYPE_DUNGEON + (1<<type);
				wk->enc_data.all.num++;
			}
		}
	}else{
		for( i=0; i<dat->num-1; i++ ){
			if( wk->dan_grid[dat->map[i]].gridx < ENC_MAP_AREA_GRID_X ){
				continue;
			}
			for( j=start; j<wk->enc_data.all.num; j++ ){
				if( wk->enc_data.all.map[j] == dat->map[i] ){
					wk->enc_data.all_type[j] |= (1<<type);
					break;
				}
			}
			if( j == wk->enc_data.all.num ){
				wk->enc_data.all.map[wk->enc_data.all.num]  = dat->map[i];
				wk->enc_data.all_type[wk->enc_data.all.num] = ENC_MAP_TYPE_DUNGEON + (1<<type);
				wk->enc_data.all.num++;
			}
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 分布リストのソート位置を取得
 *
 * @param	zoneID	ゾーンＩＤ
 *
 * @return	ソート位置
 */
//--------------------------------------------------------------------------------------------
static u32 EncListSortPosGet( u32 zoneID )
{
	u32	i;

	for( i=0; i<NELEMS(EncListSortZoneTbl); i++ ){
		if( EncListSortZoneTbl[i] == zoneID ){
			return i;
		}
	}
	GF_ASSERT( 0 );		// ここにはこないハズ
	return 0;
}

//--------------------------------------------------------------------------------------------
/**
 * 分布リストをソート
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void EncListSort( ZKN2_WORK * wk )
{
	u32	z1, z2;
	u16	i, j;

	for( i=1; i<wk->enc_data.all.num-1; i++ ){
		z1 = ZKN2MAIN_ZoneIDGetPos( wk, i );
		for( j=i+1; j<wk->enc_data.all.num; j++ ){
			z2 = ZKN2MAIN_ZoneIDGetPos( wk, j );
			if( EncListSortPosGet(z1) > EncListSortPosGet(z2) ){
				s32	tmp_map;
				u32	tmp_type;

				tmp_map = wk->enc_data.all.map[i];
				wk->enc_data.all.map[i] = wk->enc_data.all.map[j];
				wk->enc_data.all.map[j] = tmp_map;

				tmp_type = wk->enc_data.all_type[i];
				wk->enc_data.all_type[i] = wk->enc_data.all_type[j];
				wk->enc_data.all_type[j] = tmp_type;

				z1 = z2;
			}
		}
	}
}


//--------------------------------------------------------------------------------------------
/**
 * 分布リストの位置がフィールドかダンジョンか
 *
 * @param	wk		図鑑画面ワーク
 *
 * @retval	"0 = フィールド"
 * @retval	"1 = ダンジョン"
 */
//--------------------------------------------------------------------------------------------
u32 ZKN2MAIN_EncPosTypeGet( ZKN2_WORK * wk, u32 pos )
{
	if( wk->enc_data.all_type[pos] & ENC_MAP_TYPE_DUNGEON ){
		return 1;	// ダンジョン
	}
	return 0;		// フィールド
}

//--------------------------------------------------------------------------------------------
/**
 * 分布リストの位置のエンカウントタイプ状況取得
 *
 * @param	wk		図鑑画面ワーク
 * @param	pos		リスト位置
 * @param	type	エンカウントタイプ ( 0 = 通常, 1 = 特殊 )
 *
 * @retval	"0 = 指定タイプのエンカウントはしない"
 * @retval	"1 = 指定タイプのエンカウントをする"
 *
 *	通常/特殊のエンカウントをするか
 */
//--------------------------------------------------------------------------------------------
u32 ZKN2MAIN_EncTypeCheck( ZKN2_WORK * wk, u32 pos, u32 type )
{
	return ( wk->enc_data.all_type[pos] & (1<<type) );
}

//--------------------------------------------------------------------------------------------
/**
 * 分布リストの位置のゾーンＩＤ取得
 *
 * @param	wk		図鑑画面ワーク
 * @param	pos		リスト位置
 *
 * @return	ゾーンＩＤ
 */
//--------------------------------------------------------------------------------------------
u32 ZKN2MAIN_ZoneIDGetPos( ZKN2_WORK * wk, u32 pos )
{
	if( ZKN2MAIN_EncPosTypeGet( wk, pos ) == 0 ){
		return ZKN2MAIN_FldZoneIDGet( wk->enc_data.all.map[pos] );
	}
	return ZKN2MAIN_DanZoneIDGet( wk->enc_data.all.map[pos] );
}

//--------------------------------------------------------------------------------------------
/**
 * フィールド分布データのゾーンＩＤ取得
 *
 * @param	map		分布マップ番号
 *
 * @return	ゾーンＩＤ
 *
 * @li	図鑑のマップ番号からゾーンＩＤを取得
 */
//--------------------------------------------------------------------------------------------
u32 ZKN2MAIN_FldZoneIDGet( u32 map )
{
	return ZKN_FLD_RANGEID_ZONEID[map];
}

//--------------------------------------------------------------------------------------------
/**
 * ダンジョン分布データのゾーンＩＤ取得
 *
 * @param	map		分布マップ番号
 *
 * @return	ゾーンＩＤ
 *
 * @li	図鑑のマップ番号からゾーンＩＤを取得
 */
//--------------------------------------------------------------------------------------------
u32 ZKN2MAIN_DanZoneIDGet( u32 map )
{
	return ZKN_DAN_RANGEID_ZONEID[map];
}

//--------------------------------------------------------------------------------------------
/**
 * ２番道路チェック
 *
 * @param	map		分布マップ番号
 *
 * @retval	"TRUE = ２番道路"
 * @retval	"FALSE = それ以外"
 */
//--------------------------------------------------------------------------------------------
BOOL ZKN2MAIN_ZoneIDRoad2Check( u32 map )
{
	u32	zoneID = ZKN2MAIN_FldZoneIDGet( map );

	// ２番道路のエンカウント場所はこの２つのみ
	if( zoneID == ZONE_ID_R02 || zoneID == ZONE_ID_R02R0101 ){
		return TRUE;
	}
	return FALSE;
}

//--------------------------------------------------------------------------------------------
/**
 * ２番道路の分布マップ番号取得
 *
 * @param	none
 *
 * @return	分布マップ番号
 */
//--------------------------------------------------------------------------------------------
u32 ZKN2MAIN_ZoneIDRoad2PosGet(void)
{
	u32	i;

	for( i=0; i<NELEMS(ZKN_FLD_RANGEID_ZONEID); i++ ){
		if( ZKN_FLD_RANGEID_ZONEID[i] == ZONE_ID_R02 ){
			return i;
		}
	}
	return 1;	// ダミー
}

//--------------------------------------------------------------------------------------------
/**
 * １６番道路チェック
 *
 * @param	map		分布マップ番号
 *
 * @retval	"TRUE = １６番道路"
 * @retval	"FALSE = それ以外"
 */
//--------------------------------------------------------------------------------------------
BOOL ZKN2MAIN_ZoneIDRoad16Check( u32 map )
{
	u32	zoneID = ZKN2MAIN_FldZoneIDGet( map );

	// 16番道路
	if( zoneID == ZONE_ID_R16R0301 || zoneID == ZONE_ID_R16 ){
		return TRUE;
	}
	return FALSE;
}

//--------------------------------------------------------------------------------------------
/**
 * １６番道路の分布マップ番号取得
 *
 * @param	none
 *
 * @return	分布マップ番号
 */
//--------------------------------------------------------------------------------------------
u32 ZKN2MAIN_ZoneIDRoad16PosGet(void)
{
	u32	i;

	for( i=0; i<NELEMS(ZKN_FLD_RANGEID_ZONEID); i++ ){
		if( ZKN_FLD_RANGEID_ZONEID[i] == ZONE_ID_R16 ){
			return i;
		}
	}
	return 1;	// ダミー
}

//--------------------------------------------------------------------------------------------
/**
 * 分布グリッドデータ読み込み
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	nune
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_EncountGridDataLoad( ZKN2_WORK * wk )
{
	u32	siz;

	wk->fld_grid = ArcUtil_LoadEx(
					ARC_ZUKAN_ENC,
					NARC_zukan_enc_gold_zkn_fld_griddata_fldgri,
					FALSE,
					HEAPID_ZUKAN,
					ALLOC_TOP,
					&siz );

	wk->dan_grid = ArcUtil_LoadEx(
					ARC_ZUKAN_ENC,
					NARC_zukan_enc_gold_zkn_dan_griddata_dangri,
					FALSE,
					HEAPID_ZUKAN,
					ALLOC_TOP,
					&siz );
}

//--------------------------------------------------------------------------------------------
/**
 * 分布グリッドデータ解放
 *
 * @param	wk		図鑑画面ワーク
 *
 * @return	nune
 */
//--------------------------------------------------------------------------------------------
void ZKN2MAIN_EncountGridDataFree( ZKN2_WORK * wk )
{
	sys_FreeMemoryEz( wk->fld_grid );
	sys_FreeMemoryEz( wk->dan_grid );
}